今天给大家分享,在服务器上面发送邮件
服务器默认禁用了25端口,查阅了一些资料,说是得用465端口
于是就百度百度在百度,完成了通过465端口发送html样式的代码
其实很简单
我也是为了记录
怕以后要用到时忘记
所以今天分享出来
【下面是收到邮件提醒的样式】

【代码如下】
调用前,先把html的数据填好,在进行调用
懂的,改吧改吧一下就能使用了
不懂的,请评论
谢谢
/// <summary>
/// 邮件服务器地址
/// </summary>
private static string MailServer = "smtp.163.com";
/// <summary>
/// 用户名
/// </summary>
private static string MailUserName = "*****";
/// <summary>
/// 密码
/// </summary>
private static string MailPassword = "******";
public static bool SendTheEmail(string EmailTheme, string EamilContent,string ToEml)
{
try
{
System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage();
//验证
mmsg.Subject = "“Shunnet.top”提醒:" + EmailTheme.Trim();//邮件主题
mmsg.BodyFormat = System.Web.Mail.MailFormat.Html;
mmsg.Body = EamilContent;//邮件正文
mmsg.BodyEncoding = Encoding.UTF8;//正文编码
mmsg.Priority = System.Web.Mail.MailPriority.High;//优先级
mmsg.From = MailUserName;//发件者邮箱地址
mmsg.To = ToEml;//收件人收箱地址
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//登陆名
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", MailUserName);
//登陆密码
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", MailPassword);
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//端口
mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
System.Web.Mail.SmtpMail.SmtpServer = MailServer;
System.Web.Mail.SmtpMail.Send(mmsg);
return true;
}
catch (Exception ex)
{
LogHelper.Error("[邮件发送异常]" + ex.Message);
return false;
}
}
/// <summary>
/// 给用户发送邮件提醒
/// </summary>
/// <param name="UserName"></param>
/// <param name="UserStr"></param>
/// <param name="AdminName"></param>
/// <param name="AdminStr"></param>
/// <returns></returns>
public static string HtmlStr_AdminToUser(string UserName, string UserStr,string AdminName, string AdminStr,string TypeStr)
{
StringBuilder Html = new StringBuilder();
Html.Append("<div class='emailtitle' style='border-radius: 5px;border:1px solid #eee;overflow: hidden;'>");
Html.Append(" <h1 style='color:#fff;background: #3798e8;line-height:70px;font-size:18px;font-weight:normal;padding-left:40px;margin:0'>");
Html.Append(" 您在 <strong>Shunnet.top</strong> 上的“" + TypeStr + "”有回复啦");
Html.Append(" </h1>");
Html.Append(" <div class='emailtext' style='background:#fff;padding:20px 32px 40px;'>");
Html.Append("");
Html.Append(" <p style='color: #6e6e6e;font-size:15px;line-height:24px;'><strong style='color:#3798e8;'>" + UserName + "</strong> 您好!</p>");
Html.Append(" <p style='color: #6e6e6e;font-size:15px;line-height:24px;'>");
Html.Append(" 您在 <strong>Shunnet.top</strong> 的" + TypeStr + ":");
Html.Append(" <br>");
Html.Append(" </p><p style='color: #009FCC;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0'>");
Html.Append(UserStr);
Html.Append(" </p>");
Html.Append(" <p style='color: #6e6e6e;font-size:15px;line-height:24px;'>");
Html.Append(" <strong style='color:#3798e8;'>" + AdminName + "</strong> 给您回复了:");
Html.Append(" <br>");
Html.Append(" </p><p style='color: #009FCC ;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0'>" + AdminStr + "</p>");
Html.Append(" <p style='font-size:15px;line-height:24px;'>");
Html.Append(" 欢迎再度光临");
Html.Append(" <a href='https://www.shunnet.top'><strong>Shunnet.top</strong></a>");
Html.Append(" </p>");
Html.Append(" <p style='color: red;font-size:15px;line-height:24px;'>(此邮件由系统自动发出, 请勿回复。如有打扰,请见谅。)</p>");
Html.Append(" <p>");
Html.Append(" <div style='text-align:center; font-size:15px; color: #6e6e6e;'>");
Html.Append(" <span>“关注[顺网]微信公众号,了解更多更有趣的实时信息”<br></span>");
Html.Append(" <div style='text-align:center; margin-bottom:20px;'>");
Html.Append(" <img src='https://blog.shunnet.top/Accessories/images/weixinMP.png' width='150' height='150'>");
Html.Append(" </div>");
Html.Append(" </div>");
Html.Append(" </p>");
Html.Append(" </div>");
Html.Append(" <p style='color: #6e6e6e;font-size:13px;line-height:24px;text-align:right;padding:0 15px'>");
Html.Append(" 邮件发自:");
Html.Append(" <a href='https://www.shunnet.top' style='color:#51a0e3;text-decoration:none'>Shunnet.top</a>");
Html.Append(" </p>");
Html.Append("</div>");
return Html.ToString();
}
复制
记得点赞收藏哦 !!!
写了这个博客用时快两个月,到现在我都不知道要更新点啥了
神通广大的朋友们,给点意见。。。。留言给我!!!谢谢了。
本文作者:[博主]大顺
本文链接:https://shunnet.top/UvAzy2
版权声明:转载注明出处,谢谢