平台之大势何人能挡? 带着你的Net飞奔吧!
http://www.cnblogs.com/dunitian/p/4822808.html
邮箱系列:https://github.com/dunitian/LoTCodeBase/tree/master/NetCode/3.常用技能/07.Email
1.QQ邮箱:
他生成的是:http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=7oKBmoqAmq6fn8CNgYM
后来我把后面加密字符串换成明文的邮箱==》发现一样用 :http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=1054186320@qq.com
代码案例:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
官方生成代码:(其实就是把你的邮件加了下密)<br /><br />
<a target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=7oKBmoqAmq6fn8CNgYM" style="text-decoration:none;">
<img src="http://rescdn.qqmail.com/zh_CN/htmledition/images/function/qm_open/ico_mailme_12.png" />
</a>
<br /><br />
逆天通用土方法:(邮件可以任意替换)<br /><br />
<a target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=1054186320@qq.com">邮我</a>
</body>
</html>
效果:
订阅系列可以参考:http://www.cnblogs.com/dunitian/p/4554084.html
——————————————————————————————————————————————————————————————————————————————————————————————
邮件发送的前提设置:
QQ邮箱设置
授权码生成:
2.邮件案例:
简单熟悉邮件系列:点我就看基础案例(https://github.com/dunitian/LoTCodeBase/tree/master/NetCode/0.%E7%9F%A5%E8%AF%86%E6%8B%93%E5%B1%95/01.%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/3.System.Net.Mail)
代码示例:
#region 附件路径
/// <summary>
/// 附件路径
/// </summary>
public static List<string> filePathList = new List<string>();
#endregion
#region 文件上传
/// <summary>
/// LoTUploader-文件上传
/// </summary>
/// <returns></returns>
public JsonResult FileUpload(System.Web.HttpPostedFileBase file)
{
if (file == null) { return Json(new { status = false, msg = "文件提交失败" }); }
if (file.ContentLength > 10485760) { return Json(new { status = false, msg = "文件10M以内" }); }
string filterStr = ".gif,.jpg,.jpeg,.bmp,.png|.rar,.7z,.zip";
string fileExt = Path.GetExtension(file.FileName).ToLower();
if (!filterStr.Contains(fileExt)) { return Json(new { status = false, msg = "请上传图片或压缩包" }); }
//防止黑客恶意绕过,判断下文件头文件
if (!file.InputStream.CheckingExt("7173", "255216", "6677", "13780", "8297", "55122", "8075"))
{
//todo:一次危险记录
return Json(new { status = false, msg = "请上传图片或压缩包" });
}
//todo: md5判断一下文件是否已经上传过,如果已经上传直接返回 return Json(new { status = true, msg = sqlPath });
string path = string.Format("{0}/{1}", "/lotFiles", DateTime.Now.ToString("yyyy-MM-dd"));
string fileName = string.Format("{0}{1}", Guid.NewGuid().ToString("N"), fileExt);
string sqlPath = string.Format("{0}/{1}", path, fileName);
string dirPath = Request.MapPath(path);
if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); }
try
{
file.SaveAs(Path.Combine(dirPath, fileName));
file.InputStream.Dispose();
filePathList.Add(Path.Combine(dirPath, fileName));
}
catch { return Json(new { status = false, msg = "文件保存失败" }); }
return Json(new { status = true, msg = sqlPath });
}
#endregion
#region 发邮件
/// <summary>
/// 发邮件
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public async Task<JsonResult> SendMsg(MailModel model)
{
var obj = new AjaxOption<object>();
#region 校验系列
if (model == null)
{
obj.Msg = "内容不能为空";
}
if (string.IsNullOrWhiteSpace(model.MailSubject))
{
obj.Msg = "邮件主题不能为空";
}
if (string.IsNullOrWhiteSpace(model.MailContent))
{
obj.Msg = "邮件内容不能为空";
}
#region 收件人邮箱
if (model.MailToList != null)
{
foreach (var item in model.MailToList)
{
if (!item.IsEmail())
{
model.MailToList.Remove(item);
}
}
}
else
{
obj.Msg = "收件人邮箱不能为空";
}
//这个一定要加
if (model.MailToList.Count == 0)
{
obj.Msg = "收件人邮箱不能为空";
}
#endregion
if (model.MailCCList.ExistsData())
{
foreach (var item in model.MailCCList)
{
if (!item.IsEmail())
{
model.MailCCList.Remove(item);
}
}
}
#endregion
//内容解码
model.MailContent = System.Web.HttpUtility.UrlDecode(model.MailContent);
//添加附件
if (filePathList.ExistsData())
{
model.AttachmentList=filePathList;
}
if (obj.Msg.IsNullOrWhiteSpace())
obj.Status = await EmailHelper.SendAsync(model);
return Json(obj);
}
#endregion