using jmail; //之前需要安装jmail
public static bool Send(string subject, string body)
{
jmail.MessageClass mail = new MessageClass();
mail.Charset = "gb2312";
mail.ContentType = "text/html";
mail.Subject = subject; //主题
mail.Body = body; //内容
mail.Silent = true;
mail.Logging = true;
mail.Charset = "gb2312";
mail.From = "ymms@163.com";
mail.FromName = "ymm";
mail.AddRecipient("ymms@163.com", "", "");
mail.AddRecipient("zyy@mail.yitong.com.cn", "", "");
mail.MailServerUserName = "ymms";
mail.MailServerPassWord = "white coral";
mail.Priority = 3;
try
{
mail.Send("smtp.163.com", false);
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
//return false;
}
finally
{
mail.Close();
}
}
本文介绍了一个使用JMail组件发送邮件的示例代码。通过设置邮件的各项属性,如发件人、收件人、主题及内容等,并配置SMTP服务器的相关信息,实现了从指定邮箱发送邮件的功能。

663

被折叠的 条评论
为什么被折叠?



