winform 发邮件

System.Net.Mail.SmtpClient client =  new  SmtpClient( "smtp.163.com" );
 
client.UseDefaultCredentials =  false ;
client.Credentials =  new  System.Net.NetworkCredential( "[email protected]" "密码" );
client.DeliveryMethod = SmtpDeliveryMethod.Network;
 
MailAddress addressFrom =  new  MailAddress( "[email protected]" "我" );
MailAddress addressTo =  new  MailAddress( "[email protected]" );
 
System.Net.Mail.MailMessage message =  new  MailMessage(addressFrom, addressTo);
message.Subject =  "主题" ;
message.Body =  "正文" ;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
message.Attachments.Add( new  Attachment( @"c:\1.txt" ));
message.Sender =  new  MailAddress( "[email protected]" );
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml =  false ;
 
client.Send(message); 

你可能感兴趣的:(WinForm)