Sending a multipart/alternative email in C# 
Author Message
 Sending a multipart/alternative email in C#

I wrote a mass mailer for one of my clients, and I would like to add the
ability to send mulipart/alternative emails with the thing so that their
  customers with text-only mail clients don't freak out by having to
deal with reams of ugly generated HTML (hey - I wrote the app, not the
emails they're sending...).

Anybody know how to do this without having to resort to sockets? The
System.Web.Mail.MailMessage class isn't really cutting it. I'd like to
just slip in my own custom header, and then send the message.

Any help would be appreciated, as I really don't want to have to code
another frikkin' SMTP library.



Wed, 08 Dec 2004 00:49:55 GMT  
 Sending a multipart/alternative email in C#
If you just want to add a header to the mail message you can do it like
this:

MailMessage msg = new MailMessage();
msg.Subject = ...
msg.From = ...
msg.To = ...
msg.Body = ...
msg.Headers["organization"] = "Some Company, Inc.";
SmtpMail.Send(receipt);

You can also add other headers. It appears that if you don't use a standard
header then you get an error at run-time (although I cannot find a list of
the headers allowed in the docs).

-glenn-



Quote:
> I wrote a mass mailer for one of my clients, and I would like to add the
> ability to send mulipart/alternative emails with the thing so that their
>   customers with text-only mail clients don't freak out by having to
> deal with reams of ugly generated HTML (hey - I wrote the app, not the
> emails they're sending...).

> Anybody know how to do this without having to resort to sockets? The
> System.Web.Mail.MailMessage class isn't really cutting it. I'd like to
> just slip in my own custom header, and then send the message.

> Any help would be appreciated, as I really don't want to have to code
> another frikkin' SMTP library.



Wed, 08 Dec 2004 07:00:43 GMT  
 Sending a multipart/alternative email in C#

Quote:
>I wrote a mass mailer for one of my clients, and I would like to add the
>ability to send mulipart/alternative emails with the thing so that their
>  customers with text-only mail clients don't freak out by having to
>deal with reams of ugly generated HTML (hey - I wrote the app, not the
>emails they're sending...).

I'm pretty sure you aren't going to be able to handle that situation with the
.Net MailMessage object...

Quote:
>Any help would be appreciated, as I really don't want to have to code
>another frikkin' SMTP library.

An SMTP component is the least of your worries, especially since there are
several free ones available in source form.

The more difficult issue is the correct handling of multipart mime messages.
For that I'd like to suggest that a commercial component will save you a lot of
time, and especially the one I wrote which can be found at www.abderaware.com.
:-)

Using Mime.Net the following code creates a text+html multipart message:

private void SimpleHtml()
{
        string PlainText = "Hi there!";
        string HtmlText =
        "<HTML><BODY bgColor=#ffffeeee><DIV><FONT size=4>" +
        PlainText +
        "</FONT></DIV></BODY></HTML>";
        //
        // Create a multipart alternative message.  Note that both
        // parts are text without encoding, one is text/plain and the
        // other is text/html.
        //
        Mime.HtmlMessage msg = new Mime.HtmlMessage(PlainText, HtmlText);

        msg.Subject = "test";


        //
        // Save message to disk and Dispose
        //
        msg.WriteToFile(Filename.Text);
        msg.Dispose();

Quote:
}

--

*--------={ Fine Art for .NET }=--------*

*---------------------------------------*

       Turn on, tune in, download.



Wed, 08 Dec 2004 08:38:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. C#: Sending Lotus Notes email messages

2. Sending Email Help (C#)

3. Send Email from C# via Outlook

4. Ho can i send a multipart request to a java server

5. sending email from MFC dialog. (automatically send an email)

6. Send SMTP Email _WITHOUT IIS_?

7. sending email from within an application...

8. Email Bulk Send

9. Export a Crystal Report and send it by email

10. Attempting To Send Email From ASPX Web Form

11. Sending email

12. sending email

 

 
Powered by phpBB® Forum Software