• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
轻装前行
博客园    首页    新随笔    联系   管理    订阅  订阅
ASP.NET MVC 3 中 WebMail 使用的简单例子

直接贴代码了:

        public static bool SendMail(string emailTo, string emailTitle, string emailContent ,  out string errorMessage, string[] filePath = null, string[] additionalHeaders = null)
{
WebMail.SmtpServer = "smtp.gmail.com";//获取或设置要用于发送电子邮件的 SMTP 中继邮件服务器的名称。
WebMail.SmtpPort = 25;//发送端口
WebMail.EnableSsl = true;//是否启用 SSL GMAIL 需要 而其他都不需要 具体看你在邮箱中的配置
WebMail.UserName = "xxx";//账号名
WebMail.From = "xxx@gmail.com";//邮箱名
WebMail.Password = "xxx123456";//密码
WebMail.SmtpUseDefaultCredentials = true;//是否使用默认配置
errorMessage = null;
try
{
WebMail.Send(to: emailTo, subject: emailTitle, body: emailContent, isBodyHtml: true, filesToAttach: filePath, additionalHeaders: additionalHeaders);
return true;
}
catch (Exception e)
{
errorMessage = e.Message;
return false;
}
}

public static bool SendMail(string emailTo, string emailTitle, string emailContent, out string errorMsg)
{
bool flag = SendMail(emailTo, emailTitle, emailContent, out errorMsg);
return flag;
}

 

 

谢谢浏览!

posted on 2012-03-27 11:16  轻装前行  阅读(1189)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3