Constructing a MailMessage

Constructing a MailMessage object exposes further options, including the ability to add attachments:


using System;
using System.Net;
using System.Net.Mail;

using System.Threading;
using System.IO;
using System.Text;
class ThreadTest
{
    static void Main()
    {
        SmtpClient client = new SmtpClient(); 
        client.Host = "mail.myisp.net"; 
        MailMessage mm = new MailMessage();

        mm.Sender = new MailAddress("J@domain.com", "J"); 
        mm.From = new MailAddress("k@domain.com", "k"); 
        mm.To.Add(new MailAddress("b@domain.com", "b")); 
        mm.CC.Add(new MailAddress("d@domain.com", "d")); 
        mm.Subject = "Hello!";
        mm.Body = "Hi there. ";
        mm.IsBodyHtml = false;
        mm.Priority = MailPriority.High;

        Attachment a = new Attachment("photo.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg);
        mm.Attachments.Add(a);
        client.Send(mm);

    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.