62,046
社区成员
发帖
与我相关
我的任务
分享
MailMessage msg = new MailMessage(fromMail,toMail,subject,body);
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential(UserName, Password);
smtp.Port = Port;
smtp.Host = ServerName;
smtp.EnableSsl = true;
smtp.Send(msg);
public bool TestSendMail()
{
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
try
{
mail.To = txtEmailAddress.Text;
mail.From = UserName;
mail.Subject = "subject";
mail.BodyFormat = System.Web.Mail.MailFormat.Html;
mail.Body = "body";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password); //set your password here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", Port);//set port
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//set is ssl
System.Web.Mail.SmtpMail.SmtpServer = ServerName;
System.Web.Mail.SmtpMail.Send(mail);
return true;
}
catch (Exception ex)
{
ex.ToString();
}
return false;
}