About

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

Read more ...

Blog Search


(Supports AND)

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

In the beginning there was nothing, and God said, "Let there be light!" Then there was still nothing, but at least you could see it.

Flying Karamazov Brothers



Navigation





<April 2025>
SMTWTFS
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

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  
  RSS  
  RSS  
  RSS  
  RSS  

Contact Me

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 9/4/2024

Totals
Posts - 2655
Comments - 2678
Hits - 2,734,225

Averages
Entries/day - 0.33
Comments/entry - 1.01
Hits/day - 344

Updated every 30 minutes. Last: 7:32 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]   ,

|