发布邮件 查看第一个方法就可以了,第二个跟这个无关

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Data;
  6. using System.Net.Http;
  7. using System.Web.Http;
  8. using System.Web.Http.Cors;
  9. using System.Text;
  10. using System.Web;
  11. using System.Drawing;
  12. using System.Drawing.Imaging;
  13. using System.IO;
  14. using System.Threading;
  15. using LmsApiSample.Functions;
  16. using LmsApiSample.Models;
  17. using LmsApiSample.Areas.Models;
  18. using LmsApiSample.DAL;
  19. using ThoughtWorks;
  20. using ThoughtWorks.QRCode;
  21. using ThoughtWorks.QRCode.Codec;
  22. using ThoughtWorks.QRCode.Codec.Data;
  23.  
  24. namespace LmsApiSample.Areas.Training.Controllers
  25. {
  26. public class TrainingRelation
  27. {
  28. //定时任务发送邮件
  29. public void SendTeacherEmail()
  30. {
  31. List<lmsTraining> TrainingList = GetTrainingListForSendEmail();
  32. SendTeacherEmailRecordDAL dao = new SendTeacherEmailRecordDAL();
  33. if (TrainingList.Count > )
  34. {
  35. foreach (var training in TrainingList)
  36. {
  37. List<lmsTeacher> TeacherList = GetTeacherListForSendEmail(training.TrainingID);
  38. List<lmsUserInfo> UserList = GetUserInfoForSendEmail(training.TrainingID, training.IsApprove);
  39. string content = GetTemplateByUserInfoForSendEmail(UserList);
  40. string TrainingName = training.TrainingName;
  41. string fileName = TrainingName + DateTime.Now.ToString("yyyyMMddHHmmssfff");
  42. string path = AppDomain.CurrentDomain.BaseDirectory+"UpLoad\\QRCode\\" + fileName + ".png";
  43. GenerateCode(training.TrainingID, path);
  44. //发送邮件
  45. foreach (var t in TeacherList)
  46. {
  47. DataTable dt = dao.GetList(" TrainingID=" + training.TrainingID + " and TeacherID=" + t.teacherID).Tables[];
  48. if (dt == null || dt.Rows.Count == )
  49. {
  50. MailInfo mailInfo = new MailInfo
  51. {
  52. Receiver = t.Email,
  53. ReceiverName = t.teacherName,
  54. Subject = TrainingName + "培训邮件发送",
  55. Body = content
  56. };
  57. SendMail.SendEmail(mailInfo, path, TrainingName + ".png");
  58. SendTeacherEmailRecord record = new SendTeacherEmailRecord();
  59. record.TeacherID = t.teacherID;
  60. record.TrainingID = training.TrainingID;
  61. record.Content = content;
  62. record.UpdateTime = DateTime.Now;
  63. record.CreateTime = DateTime.Now;
  64. dao.Add(record);
  65.  
  66. }
  67. }
  68. }
  69. }
  70. }
  71.  
  72. //培训讲师编辑发送邮件
  73. public void SendTeacherEmailByModify(int TrainingID)
  74. {
  75. lmsTrainingDAL tdao=new lmsTrainingDAL ();
  76. lmsTraining training = tdao.GetModel(TrainingID);
  77.  
  78. SendTeacherEmailRecordDAL dao = new SendTeacherEmailRecordDAL();
  79. List<lmsTeacher> TeacherList = GetTeacherListForSendEmail(training.TrainingID);
  80. List<lmsUserInfo> UserList = GetUserInfoForSendEmail(training.TrainingID, training.IsApprove);
  81. string content = GetTemplateByUserInfoForSendEmail(UserList);
  82. string TrainingName = training.TrainingName;
  83. string fileName = TrainingName + DateTime.Now.ToString("yyyyMMddHHmmssfff");
  84. string path = System.Web.HttpContext.Current.Server.MapPath("~/UpLoad/QRCode/").ToString() + fileName + ".png";
  85. GenerateCode(training.TrainingID, path);
  86. //发送邮件
  87. foreach (var t in TeacherList)
  88. {
  89. DataTable dt = dao.GetList(" TrainingID=" + training.TrainingID + " and TeacherID=" + t.teacherID).Tables[];
  90. if (dt == null || dt.Rows.Count == )
  91. {
  92. MailInfo mailInfo = new MailInfo
  93. {
  94.  
  95. Receiver = t.Email,
  96. ReceiverName = t.teacherName,
  97. Subject = TrainingName + "培训邮件发送",
  98. Body = content
  99. };
  100. SendMail.SendEmail(mailInfo, path, TrainingName+".png");
  101. SendTeacherEmailRecord record = new SendTeacherEmailRecord();
  102. record.TeacherID = t.teacherID;
  103. record.TrainingID = training.TrainingID;
  104. record.Content = content;
  105. record.UpdateTime = DateTime.Now;
  106. record.CreateTime = DateTime.Now;
  107. dao.Add(record);
  108.  
  109. }
  110. }
  111. }
  112.  
  113. public List<lmsTraining> GetTrainingListForSendEmail()
  114. {
  115. List<lmsTraining> list = new List<lmsTraining>();
  116. lmsTrainingDAL dao = new lmsTrainingDAL();
  117. DataTable dt = dao.GetList(" cast(convert(varchar(100),dateadd(day,-1,TrainingStartTime),12) as varchar(100))=convert(varchar(100),getdate(),12)").Tables[];
  118. for (var i = ; i < dt.Rows.Count; i++)
  119. {
  120. lmsTraining model = dao.DataRowToModel(dt.Rows[i]);
  121. list.Add(model);
  122. }
  123. return list;
  124. }
  125.  
  126. public List<lmsTeacher> GetTeacherListForSendEmail(int TrainingID)
  127. {
  128. List<lmsTeacher> list = new List<lmsTeacher>();
  129. lmsTeacherDAL dao = new lmsTeacherDAL();
  130. DataTable dt = dao.GetList(" teacherID in (select TeacherID from TrainingTeacherRelation where TrainingID=" + TrainingID + ") ").Tables[];
  131. for (var i = ; i < dt.Rows.Count; i++)
  132. {
  133. lmsTeacher model = dao.DataRowToModel(dt.Rows[i]);
  134. list.Add(model);
  135. }
  136. return list;
  137. }
  138.  
  139. public List<lmsUserInfo> GetUserInfoForSendEmail(int TrainingID, bool IsApprove)
  140. {
  141. List<lmsUserInfo> list = new List<lmsUserInfo>();
  142. lmsUserInfoDAL dao = new lmsUserInfoDAL();
  143. string condition = string.Empty;
  144. if (IsApprove)
  145. {
  146. condition += " and State=1";
  147. }
  148. DataTable dt = dao.GetList(" user_id in (select UserID from lmsEnrolling where IsCancel=0 and TrainingID=" + TrainingID + condition + ")").Tables[];
  149. for (var i = ; i < dt.Rows.Count; i++)
  150. {
  151. lmsUserInfo model = dao.DataRowToModel(dt.Rows[i]);
  152. list.Add(model);
  153. }
  154. return list;
  155. }
  156.  
  157. public string GetTemplateByUserInfoForSendEmail(List<lmsUserInfo> list)
  158. {
  159.  
  160. StringBuilder strBuilder = new StringBuilder();
  161. lmsAreaInfoDAL dao = new lmsAreaInfoDAL();
  162. if (list != null && list.Count > )
  163. {
  164.  
  165. strBuilder.Append("<table>");
  166. strBuilder.Append("<tr>");
  167. strBuilder.Append("<th>经销商</th>");
  168. strBuilder.Append("<th>姓名</th>");
  169. strBuilder.Append("<th>PIN</th>");
  170. strBuilder.Append("</tr>");
  171. foreach (var l in list)
  172. {
  173. //lmsAreaInfo info = new lmsAreaInfo();
  174. //DataTable dt = dao.GetList(" area_id=").Tables[0];
  175. lmsAreaInfo info = dao.GetModel(Convert.ToInt32(l.user_area3_id));
  176. if (info != null)
  177. {
  178. strBuilder.Append("<tr>");
  179. strBuilder.Append("<td>" + info.area_name + "</td>");
  180. strBuilder.Append("<td>" + l.user_name + "</td>");
  181. strBuilder.Append("<td>" + l.login_name + "</td>");
  182. strBuilder.Append("</tr>");
  183. }
  184. }
  185. strBuilder.Append("<table>");
  186. }
  187. return strBuilder.ToString();
  188. }
  189.  
  190. #region 生成二维码链接
  191. ////Base64浏览图片 (浏览器不兼容)
  192. //public string GenerateCode(int TrainingID)
  193. //{
  194. // try
  195. // {
  196. // string str = System.Configuration.ConfigurationManager.AppSettings["MobileDomain"] + "/lmsViews/wechat/index.html#/main/signIn?TrainingID=" + TrainingID;
  197. // //初始化二维码生成工具
  198. // QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
  199. // qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
  200. // qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
  201. // qrCodeEncoder.QRCodeVersion = 0;
  202. // qrCodeEncoder.QRCodeScale = 4;
  203. // //将字符串生成二维码图片
  204. // Bitmap image = qrCodeEncoder.Encode(str, Encoding.Default);
  205. // //保存为PNG到内存流
  206. // MemoryStream ms = new MemoryStream();
  207.  
  208. // image.Save(ms, ImageFormat.Png);
  209. // string strUrl = "data:image/gif;base64," + Convert.ToBase64String(ms.ToArray());
  210. // image.Dispose();
  211. // ms.Dispose();
  212.  
  213. // return strUrl;
  214. // }
  215. // catch (Exception e)
  216. // {
  217. // ///修改为单例访问日志记录对象
  218. // LogConcel.GetLogInstance.WriteExceptionLog(e, "Method:GenerateCode");
  219. // return null;
  220. // }
  221. //}
  222.  
  223. public void GenerateCode(int TrainingID, string path)
  224. {
  225. //删除同名的图片
  226. //if (File.Exists(path))
  227. //{
  228. // Thread.Sleep(2000);
  229. // File.Delete(path);
  230. //}
  231. //生成二维码
  232. string str = System.Configuration.ConfigurationManager.AppSettings["MobileDomain"] + "/lmsViews/wechat/index.html#/main/signIn?TrainingID=" + TrainingID;
  233. //初始化二维码生成工具
  234. QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
  235. qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
  236. qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
  237. qrCodeEncoder.QRCodeVersion = ;
  238. qrCodeEncoder.QRCodeScale = ;
  239. //将字符串生成二维码图片
  240. Bitmap image = qrCodeEncoder.Encode(str, Encoding.Default);
  241. image.Save(path, System.Drawing.Imaging.ImageFormat.Png);
  242. image.Dispose();
  243. }
  244.  
  245. #endregion
  246. }
  247. }

Global.cs

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Http.Formatting;
  5. using System.Web;
  6. using System.Web.Http;
  7. using System.Web.Mvc;
  8. using System.Web.Optimization;
  9. using System.Web.Routing;
  10.  
  11. namespace LmsApiSample
  12. {
  13. public class WebApiApplication : System.Web.HttpApplication
  14. {
  15. protected void Application_Start()
  16. {
  17. AreaRegistration.RegisterAllAreas();
  18. TimeTaskConfig.BeginTask();
  19. GlobalConfiguration.Configure(WebApiConfig.Register);
  20. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  21. RouteConfig.RegisterRoutes(RouteTable.Routes);
  22. BundleConfig.RegisterBundles(BundleTable.Bundles);
  23. GlobalConfiguration.Configuration.EnableCors();
  24. log4net.Config.XmlConfigurator.Configure();
  25. GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("json", "true", "application/json"));
  26. }
  27. }
  28. }

里面添加了TimeTaskConfig

TimeTaskConfig类

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Timers;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using LmsApiSample.Areas.Training.Controllers;
  9.  
  10. namespace LmsApiSample
  11. {
  12. public class TimeTaskConfig
  13. {
  14.  
  15. public static void BeginTask()
  16. {
  17. //定义定时器
  18. //1000表示1秒的意思
  19. System.Timers.Timer myTimer = new System.Timers.Timer(*);
  20. //设置是执行一次(false)还是一直执行(true);
  21. myTimer.AutoReset = true;
  22. //是否执行System.Timers.Timer.Elapsed事件;
  23. myTimer.Enabled = true;
  24. //到达时间的时候执行事件(theout方法);
  25. myTimer.Elapsed += new System.Timers.ElapsedEventHandler(ElapsedEvent);
  26. }
  27.  
  28. public static void ElapsedEvent(object source, System.Timers.ElapsedEventArgs e)
  29. {
  30. try
  31. {
  32. CallWithTimeout(WorkTask, **);
  33. }
  34. catch (Exception ex)
  35. {
  36. //
  37. }
  38. }
  39.  
  40. public static void WorkTask()
  41. {
  42. //定时发送给讲师培训邮件
  43. //每天九点的时间发送邮件
  44. if (DateTime.Now.Hour == )
  45. {
  46. new TrainingRelation().SendTeacherEmail();
  47. }
  48. }
  49. /// <summary>
  50. ///
  51. /// </summary>
  52. /// <param name="action">任务</param>
  53. /// <param name="timeoutMilliseconds">多长时间回收线程</param>
  54. public static void CallWithTimeout(Action action, int timeoutMilliseconds)
  55. {
  56. Thread threadToKill = null;
  57. Action wrappedAction = () =>
  58. {
  59. threadToKill = Thread.CurrentThread;
  60. action();
  61. };
  62.  
  63. IAsyncResult result = wrappedAction.BeginInvoke(null, null);
  64. if (result.AsyncWaitHandle.WaitOne(timeoutMilliseconds))
  65. {
  66. wrappedAction.EndInvoke(result);
  67. }
  68. else
  69. {
  70. threadToKill.Abort();
  71. //LogHelper.Error(typeof(ImportAttendanceData), "超时抛出");
  72. //throw new TimeoutException();
  73. }
  74. }
  75. }
  76.  
  77. }

上面用到的上传邮件的类

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Net;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Net.Mail;
  8. using System.Net.Mime;
  9. using System.IO;
  10. using System.Timers;
  11. using System.Xml;
  12.  
  13. namespace LmsApiSample.Functions
  14. {
  15. /// <summary>
  16. /// 发送邮件的信息
  17. /// </summary>
  18. public class MailInfo
  19. {
  20. /// <summary>
  21. /// 主题行
  22. /// </summary>
  23. private string _subject;
  24.  
  25. /// <summary>
  26. /// 接收者名字
  27. /// </summary>
  28. public string ReceiverName { get; set; }
  29.  
  30. /// <summary>
  31. /// 接收者邮箱(多个用英文“,”号分割)
  32. /// </summary>
  33. public string Receiver { get; set; }
  34.  
  35. /// <summary>
  36. /// 邮件的主题行
  37. /// </summary>
  38. public string Subject
  39. {
  40. get
  41. {
  42. if (string.IsNullOrEmpty(_subject) && _subject.Length > )
  43. {
  44. return Body.Substring(, );
  45. }
  46. return _subject;
  47. }
  48. set { _subject = value; }
  49. }
  50.  
  51. /// <summary>
  52. /// 正文内容
  53. /// </summary>
  54. public string Body { get; set; }
  55.  
  56. /// <summary>
  57. /// 抄送人集合
  58. /// </summary>
  59. public string CC { get; set; }
  60.  
  61. /// <summary>
  62. /// 回复地址
  63. /// </summary>
  64. public string Replay { get; set; }
  65. }
  66. /// <summary>
  67. /// 邮件配置信息
  68. /// </summary>
  69. //[JsonObject]
  70. public class MailConfig
  71. {
  72. private string _path = string.Empty;
  73.  
  74. /// <summary>
  75. /// 主机名 如:smtp.163.com
  76. /// </summary>
  77. //[JsonProperty]
  78. public string Host { get; set; }
  79.  
  80. /// <summary>
  81. /// 端口号 如:25
  82. /// </summary>
  83. //[JsonProperty]
  84. public int Port { get; set; }
  85.  
  86. /// <summary>
  87. /// 用户名
  88. /// </summary>
  89. //[JsonProperty]
  90. public string User { get; set; }
  91.  
  92. /// <summary>
  93. /// 密码
  94. /// </summary>
  95. //[JsonProperty]
  96. public string Password { get; set; }
  97.  
  98. /// <summary>
  99. /// 是否包含Html代码
  100. /// </summary>
  101. //[JsonProperty]
  102. public bool IsHtml { get; set; }
  103.  
  104. /// <summary>
  105. /// 发送者显示名
  106. /// </summary>
  107. //[JsonProperty]
  108. public string DisplayName { get; set; }
  109.  
  110. /// <summary>
  111. /// 来源
  112. /// </summary>
  113. //[JsonProperty]
  114. public string From { get; set; }
  115.  
  116. /// <summary>
  117. /// 是否启用SSL 默认:false
  118. /// 如果启用 端口号要改为加密方式发送的
  119. /// </summary>
  120. //[JsonProperty]
  121. public bool EnableSsl { get; set; }
  122. }
  123.  
  124. /// <summary>
  125. /// 发送邮件
  126. /// </summary>
  127. public class SundayMail
  128. {
  129. private static MailConfig mailConfig;
  130.  
  131. /// <summary>
  132. /// 使用指定的 Mafly.Mail.Config 类对象初始化 Mafly.Mail 类的新实例。
  133. /// </summary>
  134. /// <param name="config">包含邮件配置信息的 Mafly.Mail.Config。</param>
  135. public SundayMail(MailConfig config)
  136. {
  137. mailConfig = config;
  138. }
  139.  
  140. /// <summary>
  141. /// 发送邮件
  142. /// </summary>
  143. /// <param name="receiver">接收人邮箱</param>
  144. /// <param name="body">邮件内容</param>
  145. public void Send(string receiver, string body)
  146. {
  147. Send(new MailInfo { Receiver = receiver, ReceiverName = receiver, Body = body, Subject = body });
  148. }
  149.  
  150. /// <summary>
  151. /// 发送邮件
  152. /// </summary>
  153. /// <param name="receiver">接收人邮箱</param>
  154. /// <param name="receiverName">接收人姓名</param>
  155. /// <param name="body">邮件内容</param>
  156. public void Send(string receiver, string receiverName, string body)
  157. {
  158. Send(new MailInfo { Receiver = receiver, ReceiverName = receiverName, Body = body, Subject = body });
  159. }
  160.  
  161. /// <summary>
  162. /// 发送邮件
  163. /// </summary>
  164. /// <param name="receiver">接收人邮箱</param>
  165. /// <param name="receiverName">接收人姓名</param>
  166. /// <param name="subject">邮件主题</param>
  167. /// <param name="body">邮件内容</param>
  168. public void Send(string receiver, string receiverName, string subject, string body)
  169. {
  170. Send(new MailInfo { Receiver = receiver, ReceiverName = receiverName, Body = body, Subject = subject });
  171. }
  172.  
  173. /// <summary>
  174. /// 发送邮件
  175. /// </summary>
  176. /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
  177. /// <param name="message">默认为null。 System.Net.Mail.MailMessage </param>
  178. public void Send(MailInfo info, MailMessage message = null)
  179. {
  180. var sender = new SmtpClient();
  181. message = message ?? new MailMessage();
  182. if (string.IsNullOrEmpty(info.ReceiverName))
  183. info.ReceiverName = info.Receiver;
  184. if (info.Receiver.Contains(","))
  185. message.To.Add(info.Receiver);
  186. else
  187. message.To.Add(new MailAddress(info.Receiver, info.ReceiverName));
  188.  
  189. message.Subject = info.Subject;
  190. if (!string.IsNullOrEmpty(info.Replay))
  191. message.ReplyToList.Add(new MailAddress(info.Replay));
  192. message.Body = info.Body;
  193. if (!string.IsNullOrEmpty(info.CC))
  194. message.CC.Add(new MailAddress(info.CC));
  195. try
  196. {
  197. message.IsBodyHtml = mailConfig.IsHtml;
  198. message.From = new MailAddress(mailConfig.From, mailConfig.DisplayName);
  199. sender.Host = mailConfig.Host;
  200. sender.Port = mailConfig.Port;
  201. sender.UseDefaultCredentials = false;
  202. sender.Credentials = new NetworkCredential(mailConfig.User, mailConfig.Password);
  203. sender.DeliveryMethod = SmtpDeliveryMethod.Network;
  204. sender.EnableSsl = mailConfig.EnableSsl;
  205. sender.Send(message);
  206. }
  207. catch (Exception ex)
  208. {
  209. message.From = new MailAddress("NuGets@163.com", "NuGet_Mafly");
  210. message.IsBodyHtml = true;
  211. sender.Host = "smtp.163.com";
  212. sender.Port = ;
  213. sender.UseDefaultCredentials = false;
  214. sender.Credentials = new NetworkCredential("NuGets@163.com", "vzihlbquwnriqlht");
  215. sender.DeliveryMethod = SmtpDeliveryMethod.Network;
  216. sender.EnableSsl = false;
  217. sender.Send(message);
  218. //throw new Team.Common.Exceptions.EmailConfigurationException { Status = Team.Common.Enums.EmailConfiguration.ConfigurationError };
  219. }
  220. // sender.Send(message);
  221. }
  222.  
  223. /// <summary>
  224. /// 发送邮件(带附件)
  225. /// </summary>
  226. /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
  227. /// <param name="attachments">附件列表 System.Net.Mail.Attachment </param>
  228. public void Send(MailInfo info, params Attachment[] attachments)
  229. {
  230. var message = new MailMessage();
  231. foreach (var item in attachments)
  232. {
  233. message.Attachments.Add(item);
  234. }
  235. try
  236. {
  237. Send(info, message);
  238. }
  239. catch (Exception e)
  240. {
  241. throw e;
  242. }
  243. }
  244.  
  245. /// <summary>
  246. /// 发送邮件(带附件)
  247. /// </summary>
  248. /// <param name="info">接收人信息 Mafly.Mail.MailInfo </param>
  249. /// <param name="filePath">附件路径 System.String </param>
  250. public void Send(MailInfo info, string filePath)
  251. {
  252. var message = new MailMessage();
  253. message.Attachments.Add(new Attachment(filePath));
  254. Send(info, message);
  255. }
  256. }
  257.  
  258. public class SendMail
  259. {
  260. private static string emailAccount = ConfigurationManager.AppSettings["emailAccount"];
  261. private static string emailPass = ConfigurationManager.AppSettings["emailPassword"];
  262. private static string emailDisplyName = ConfigurationManager.AppSettings["emailDisplyName"];
  263. private static string smtp = ConfigurationManager.AppSettings["smtp"];
  264.  
  265. private static SundayMail mailservice;
  266. static SendMail()
  267. {
  268. MailConfig config = new MailConfig
  269. {
  270. IsHtml = true,
  271. Port = ,
  272. User = emailAccount,
  273. Password = emailPass,
  274. EnableSsl = false,
  275. From = emailAccount,
  276. DisplayName = emailDisplyName,
  277. Host = smtp
  278.  
  279. };
  280. mailservice = new SundayMail(config);
  281. }
  282.  
  283. public static void SendEmail(MailInfo mailInfo)
  284. {
  285.  
  286. mailservice.Send(mailInfo);
  287. }
  288.  
  289. public static void SendEmail (MailInfo mailInfo,string path,string name)
  290. {
  291. Attachment attachment = new Attachment(path);
  292. attachment.Name=name;
  293. mailservice.Send(mailInfo, attachment);
  294. }
  295. }
  296. }

需要注意的

在TimeTaskConfig中有个生成二维码注释掉的,用base64方式上传图片,在edge,猎豹浏览器中可以,在谷歌,火狐中不行,最后用了上传附件。

在Global中获取文件夹路径,不能使用Server.MapPath

网上查询现在有两种方式

AppDomain.CurrentDomain.BaseDirectory

HttpRuntime.AppDomainAppPath

Environment.CurrentDirectory

第3个为什么是c盘???

这个路径就是配置iis网站的路径

调试Global时,除了 要重新启动iis中的网站以外,还要重新加载该网站的任何一个页面。

MVC中定时发布二维码邮件的更多相关文章

  1. 如何通过github上传项目并在readme.md中展示图片二维码

    将本地项目上传至github   第一步:git init (创建仓库)   第二步:git add README.md (添加项目)git add *   第三步:git commit -m &qu ...

  2. 在DevExpress程序中使用条形码二维码控件,以及进行报表打印处理

    在很多业务系统里面,越来越多涉及到条形码.二维码的应用了,不管在Web界面还是WInform界面都需要处理很多物料相关的操作,甚至很多企业为了减少录入错误操作,为每个设备进行条形码.二维码的标签,直接 ...

  3. [AX2012 R3]在SSRS报表中使用QR二维码

    AX2012是自带生成QR二维码的类,可以很方便的用在SSRS报表中,下面演示如何在RDP的报表中使用二维码,首先从定义临时表开始: 字段URL是要用于二维码的字符串,QrCode是container ...

  4. pbfunc外部函数扩展应用-直接在Datawindow中生成QR二维码,非图片方式

    利用pbfunc外部函数在Datawindow中直接生成QR二维码,非图片方式.需要注意以下面几点: Datawindow的DataObject的单位必须为像素(Pixels). Datawindow ...

  5. laravel中生成支付宝 二维码 扫码支付

    文档教程模拟: http://www.023xs.cn/Article/37/laravel5%E9%9B%86%E6%88%90%E6%94%AF%E4%BB%98%E5%AE%9Dalipay%E ...

  6. vue项目中批量打印二维码

    前提:项目中要打印的二维码为后台返回,批量选择后,点击打印,先打开二维码预览界面,再执行打印. 以下代码中 codePicList为选中的二维码数组.重点css:page-break-after:al ...

  7. 在UniApp的H5项目中,生成二维码和扫描二维码的操作处理

    在我们基于UniApp的H5项目中,需要生成一些二维码进行展示,另外也需要让用户可以扫码进行一定的快捷操作,本篇随笔介绍一下二维码的生成处理和基于H5的扫码进行操作.二维码的生成,使用了JS文件wea ...

  8. golang中生成读取二维码(skip2/go-qrcode和boombuler/barcode,tuotoo/qrcode)

     1 引言 在github上有好用golan二维码生成和读取库,两个生成二维码的qrcode库和一个读取qrcode库. skip2/go-qrcode生成二维码,github地址:https://g ...

  9. 在vue中实现扫描二维码跳转页面

    文字少的博文不允许发布到网站首页.文字少的博文不允许发布到网站首页.文字少的博文不允许发布到网站首页.文字少的博文不允许发布到网站首页.文字少的博文不允许发布到网站首页.文字少的博文不允许发布到网站首 ...

随机推荐

  1. HTTP/2笔记之错误处理和安全

    零.前言 这里整理了一下错误和安全相关部分简单记录. 一.HTTP/2错误 1. 错误定义 HTTP/2定义了两种类型错误: 导致整个连接不可使用的错误为连接错误(connection error) ...

  2. 对cookie的重新认识

    这两天做了一个跟cookie打交道比较多的项目,把其中重新认识的点记录下来: 1.$.cookie(name, value, time),当time为0时,相当于本句没有执行,并不会将原本记录在用户浏 ...

  3. BluePrint和ORM

    一.蓝图创建 #引入库文件 from flask import Blueprint,request,jsonify user = Blueprint( "site", __name ...

  4. ZoomIt v4.5

    https://technet.microsoft.com/en-us/sysinternals/bb897434.aspx zoomIt: 演示必备辅助软件 ZoomIt(主页|介绍)是一款非常实用 ...

  5. Jmeter中ftp测试下载默认路径及文件

    今天在测试一个FTP下载功能接口时,发现根据官方文档下载可以成功,但找不到文件,管方文档的配置图如下: 根据官方文档,自己建立了一个请求如下: 但实际下载成功时却发现找不到文件 原来,奥秘是: 本地文 ...

  6. 【JavaScript算法】---插入排序

    一.什么叫做插入排序法 有一个已经有序的数据序列,要求在这个已经排好的数据序列中插入一个数,但要求插入后此数据序列仍然有序,这个时候就要用到一种新的排序方法——插入排序法 二.核心 插入排序的基本操作 ...

  7. RPM命令详解(安装、升级、卸载)

    rpm 常用命令1.安装一个包 # rpm -ivh 2.升级一个包 # rpm -Uvh 3.卸载一个包 # rpm -e 4.安装参数 --force 即使覆盖属于其它包的文件也强迫安装 --no ...

  8. ora-00600错误解决一枚

    今天网友遇到ora-600错误,这里把这个ora-600错误的解决方法详细记录一下. 最初报错信息如下: ora-600-图1 ora-600-图2 图3 这里我们可以看到报错控制文件版本不一致,要求 ...

  9. 分区实践 A PRIMARY KEY must include all columns in the table's partitioning function

    MySQL :: MySQL 8.0 Reference Manual :: 23 Partitioning https://dev.mysql.com/doc/refman/8.0/en/parti ...

  10. android中的验证码倒计时

    1.如图所示,要实现一个验证码的倒计时的效果                             2.实现 图中获取验证码那块是一个button按钮 关键部分,声明一个TimeCount,继承自C ...