c# Как отправить емэйл ( email ) / c# How to send email

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("tomail@mail.ru");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("frommail@mail.ru");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient _SmtpClient = new System.Net.Mail.SmtpClient("smtp.mail.ru");
_SmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.NetworkCredential _NetworkCredential = new System.Net.NetworkCredential("smtpuser", "smtppassword");
_SmtpClient.UseDefaultCredentials = false;
_SmtpClient.Credentials = _NetworkCredential;

System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment("c:\\textfile.txt");
    message.Attachments.Add(attachment);
_SmtpClient.Send(message);


вот здесь можно ещё почитать
http://www.digitalcoding.com/Code-Snippets/C-Sharp/C-Code-Snippet-Send-Email-Using-SMTP-Server.html

No comments:

Post a Comment

Note: only a member of this blog may post a comment.