namespace ConsoleApplication
{
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
public class Class1
{
static void Main(string[] args)
{
string html = "<html><body><a href=\"http://www.live.com\"><img src=\"cid:attachment1\"></a>";
html += "<script src=\"cid:attachment2\"></script>中国字";
html += "<a href=\"http://www.google.com\"><br><img src=\"cid:attachment1\"></a></body></html>";
AlternateView view = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
LinkedResource picture = new LinkedResource(@"pic.JPG", MediaTypeNames.Image.Jpeg);
picture.ContentId = "attachment1";
view.LinkedResources.Add(picture);
LinkedResource script = new LinkedResource(@"a.js", MediaTypeNames.Text.Plain);
script.ContentId = "attachment2";
view.LinkedResources.Add(script);
MailMessage mail = new MailMessage();
mail .AlternateViews.Add(view);
mail.From = new MailAddress("xxxx@gmail.com", "Microshaoft-gmail");
mail.To.Add(new MailAddress("yyyy@live.com", "Microshaoft-live"));
mail.Subject = "Linked Resource Attachment Alternate Views Smtp Client Test " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Credentials = new NetworkCredential("user","password");
client.EnableSsl = true;
client.Send(mail);
Console.WriteLine("Hello World");
Console.WriteLine(Environment.Version.ToString());
}
}
}