stmpプロトコルによるメール送信
4035 ワード
網易、新浪、グーグル、テンセントのメールサービスはstmpプロトコルをサポートしています.
using System.Net.Mail;
転載先:https://www.cnblogs.com/Kakasi/archive/2013/03/21/2973363.html
using System.Net.Mail;
MailMessage message = null;
SmtpClient client = null;
public void Send()
{
try
{
string argFrom = "[email protected]";
string argTo = "[email protected]";
string argSubject = " ";
string argBody = "test";
message = new MailMessage(argFrom, argTo, argSubject, argBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
message.Attachments.Add(new Attachment(@"D:\2e2sd42lxj.jpg"));
client = new SmtpClient("smtp.gmail.com");
client.UseDefaultCredentials = false;
//client.Port = 465; // foxmail ,
// client.Port =587;// gmail , , :
client.EnableSsl = true; // gmail ,qq
client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Timeout = 100000;
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
転載先:https://www.cnblogs.com/Kakasi/archive/2013/03/21/2973363.html