Use System. Net. Mail to send emails

Source: Internet
Author: User
Tags mailmessage smtpclient
Using System;
Using System. Net. Mail;
Using System. Net. Mime;
Using System. Net;
Using System. Collections;
Namespace ConsoleApplication1
{
Class Program
{
Static void Main (string [] args)
{
Try
{
String file = "attach.txt ";
MailMessage message = new MailMessage ("** @ 126.com"," ** @ mail2.sysu.edu.cn "," Hello "," Hello ");
Attachment data = new Attachment (file, MediaTypeNames. Application. Octet );
ContentDisposition disposition = data. ContentDisposition;
Disposition. CreationDate = System. IO. File. GetCreationTime (file );
Disposition. ModificationDate = System. IO. File. GetLastWriteTime (file );
Disposition. ReadDate = System. IO. File. GetLastAccessTime (file );
Message. Attachments. Add (data );
SmtpClient client = new SmtpClient ("smtp.126.com ");
Client. Credentials = new NetworkCredential ("** @ 126.com ","**");
Client. Send (message );
ContentDisposition cd = data. ContentDisposition;
Console. WriteLine ("Content disposition ");
Console. WriteLine (cd. ToString ());
Console. WriteLine ("File {0}", cd. FileName );
Console. WriteLine ("Size {0}", cd. Size );
Console. WriteLine ("Creation {0}", cd. CreationDate );
Console. WriteLine ("Modification {0}", cd. ModificationDate );
Console. WriteLine ("Read {0}", cd. ReadDate );
Console. WriteLine ("Inline {0}", cd. Inline );
Console. WriteLine ("Parameters: {0}", cd. Parameters. Count );
Foreach (DictionaryEntry d in cd. Parameters)
{
Console. WriteLine ("{0 }={ 1}", d. Key, d. Value );
}
Data. Dispose ();
}
Catch (Exception e)
{
Console. WriteLine (e. Message );
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.