下載處:EASendMail
// strReceiver :收件者
//strTitle:信件標題
//strBody:信件內容
//strUserName:信箱帳號
//strPW:信箱密碼
public void SendEmail(string strReceiver, string strTitle, string strBody, string strUserName, string strPW)
{
try
{
SmtpMail oMail = new SmtpMail("TryIt");
EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();
// Set sender email address, please change it to yours
oMail.From = "XXX@gamil.com";
// Set recipient email address, please change it to yours
oMail.To = strReceiver;
// Set email subject
oMail.Subject = strTitle;
// Set email body
oMail.TextBody = strBody;
// Your SMTP server address
SmtpServer oServer = new SmtpServer("smtp.gmail.com");
// User and password for ESMTP authentication, if your server doesn't require
// User authentication, please remove the following codes.
oServer.User = strUserName;
oServer.Password = strPW;
// If your smtp server requires TLS connection, please add this line
// oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
// If your smtp server requires implicit SSL connection on 465 port, please add this line
oServer.Port = 465;
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
try
{
oSmtp.SendMail(oServer, oMail);
}
catch (Exception ep)
{
MessageBox.Show(ep.Message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
來源參考
沒有留言:
張貼留言