About

I'm Mike Pope. I live in the Seattle area. I've been a technical writer and editor for over 30 years. I'm interested in software, language, music, movies, books, motorcycles, travel, and ... well, lots of stuff.

Read more ...

Blog Search


(Supports AND)

Google Ads

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

It appears from the evidence that there was never a golden age in which the rules for the use of the possessive apostrophe in English were clear-cut and known, understood, and followed by most educated people.

Tom McArthur



Navigation





<October 2014>
SMTWTFS
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Categories

  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  

Contact

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 10/16/2014

Totals
Posts - 2312
Comments - 2502
Hits - 1,677,449

Averages
Entries/day - 0.56
Comments/entry - 1.08
Hits/day - 405

Updated every 30 minutes. Last: 8:31 AM Pacific


  07:15 PM

Although "adventures" might be too, um, adventuresome a term.

Yesterday I tried my hand at using .NET 2.0 to send an email, which was partly an exercise in trying to suss out how to do that using only IntelliSense.

Today I wanted to attach a graphic and possibly embed a graphic. From the olde days of System.Web.Mail, I knew that attachments are created separately and then added to the message's attachment collection. I almost got this to work using only IntelliSense, but I must be too tired or something. I wanted to attach a .jpg file and could not figure out how to specify that. The System.Net.Mail.Attachment class supports various properties that sounded right -- ContentStream, ContentDisposition, etc. Those seemed ... like a lot of work just to add a graphic. But as noted, I'm not thinking too clearly here, and I was stumped. So I grubbed through the 2.0 docs and discovered (via a nice example, albeit one that won't compile :-) ) that I can pass a file name as a string in the Attachment constructor. D'oh. Why that was clear yesterday and not today is a mystery.

One of the parameters for the Attachment constructor is the media/content type. There's a class for this -- System.Net.Mime.ContentType -- or if you're facile with standard HTTP media types, you can pass the media type as a string. So here's how I constructed the attachment:
Dim attach As New Attachment("MyPic.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg)
or alternatively:
Dim attach As New Attachment("MyPic.jpg", "image/jpeg")
Then it's easy to add to the message:
msg.Attachments.Add(attach)
I sent this and it came through just fine as an attachment.

I've poked around with the notion of embedding, but I'm not seeing how to do this obviously, so that will be tomorrow.

I did find out one thing that I'd had a question about yesterday. Why is the MailMessage.To property read-only? Duh, it's because it's a collection. Thus:
msg.To.Add("fred@contoso.com")
msg.To.Add("mary@contoso.com")
Ok, then.

Update 12:56 pm I forgot to note that I sussed out the issue with relay permissions. As I noted yesterday, the SMTP host out-and-out refused to relay any messages that did not have a From address inside our domain. But yay, the SmtpClient class now exposes authentication stuff as proper properties (heh), not wacky extended fields like the old Mail class did. There's a Credentials property that you can use, apparently, to pass explicit credentials. But better yet, there's a UseDefaultCredentials Boolean property that I set to true and that apparently used my Windows creds to authenticate me with the Exchange server. So I was able to set To, From, CC, and ReplyTo addresses to whatever I wanted.

All of this reminds me also to speculate strongly, let us say, that the new Mail classes are no longer wrappers around CDO. They are, I believe, rewritten from first principles.

[categories]   ,

|