[Code: c #]
Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Net. Mail;
Namespace SystemNetMailTest
{
Class Program
{
Static void Main (string [] args)
{
String myMailEncoding = "UTF-8 ";
String myFromEmail = "testtest.com ";
String myFromName = "courier sender ";
String myToEmail = "testtest.com ";
String myToName = "courier receiver ";
MailAddress from =
New MailAddress (myFromEmail, myFromName,
Encoding. GetEncoding (myMailEncoding ));
MailAddress to =
New MailAddress (myToEmail, myToName,
Encoding. GetEncoding (myMailEncoding ));
MailMessage myMessage = new MailMessage (from, );
MyMessage. Subject = "Subject ";
MyMessage. SubjectEncoding = Encoding. GetEncoding (myMailEncoding );
MyMessage. Body = "\ "/> ";
MyMessage. BodyEncoding = Encoding. GetEncoding (myMailEncoding );
MyMessage. IsBodyHtml = true;
MyMessage. Priority = MailPriority. High;
// Set the Attachment statement case (Attachment)
String strFilePath = @ "C: \ Logo.gif ";
System. Net. Mail. Attachment attachment1 =
New System. Net. Mail. Attachment (strFilePath );
Attachment1.Name=System. IO. Path. GetFileName (strFilePath);
Attachment1.NameEncoding = Encoding. GetEncoding (myMailEncoding );
Attachment1.TransferEncoding = System. Net. Mime. TransferEncoding. Base64;
// Set the Attachment as an Inline Attachment)
Attachment1.ContentDisposition. Inline = true;
Attachment1.ContentDisposition. DispositionType =
System. Net. Mime. DispositionTypeNames. Inline;
MyMessage. Attachments. Add (attachment1 );
SmtpClient smtp = new SmtpClient ("localhost ");
Try
{
Smtp. Send (myMessage );
Console. WriteLine (DateTime. Now. ToString () + "sent successfully ");
}
Catch
{
Console. WriteLine (DateTime. Now. ToString () + "message loss !!! ");
}
Console. ReadKey ();
}
}
}