前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Email系列(QQ邮箱 + 含附件的邮箱案例 + 项目实战)上

Email系列(QQ邮箱 + 含附件的邮箱案例 + 项目实战)上

作者头像
逸鹏
发布2018-04-10 15:42:04
9260
发布2018-04-10 15:42:04
举报
文章被收录于专栏:逸鹏说道逸鹏说道

平台之大势何人能挡? 带着你的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

代码案例:

代码语言:html
复制
<!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)

代码示例:

代码语言:javascript
复制
#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
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2016-07-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 我为Net狂 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档