■■■

2016年4月4日月曜日

SmtpClientでSMTP認証でメール送信する方法

SmtpClientでSMTP認証でメール送信する方法
VB.NET
Dim msg As New System.Net.Mail.MailMessage( _
"from@xxx.xxx", "to@xxx.xxx", "題名", "本文")

Dim sc As New System.Net.Mail.SmtpClient()
sc.Host = "localhost"
sc.Port = 25
sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
sc.Credentials = New System.Net.NetworkCredential("user", "pass")
sc.Send(msg)

msg.Dispose()
sc.Dispose()
C#
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(
"from@xxx.xxx", "to@xxx.xxx", "題名", "本文");

System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
sc.Host = "localhost";
sc.Port = 25;
sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
sc.Credentials = new System.Net.NetworkCredential("user", "pass");
sc.Send(msg);

msg.Dispose();
sc.Dispose();

■■■