下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
异步发送电子邮件代码/// <summary> /// 异步发送电子邮件 /// </summary> /// <param name="fromEmail">发送方电子邮件</param> /// <param name="fromPwd">发送方电子邮件密码</param> /// <param name="toEmail">接收方电子邮件</param> /// <param name="subject">邮件标题</param> /// <param name="body">邮件内空</param> /// <param name="emailType">邮件类型</param> smtp.163.com.cn; smtp.qq.com.cn; smtp.126.com.cn; smtp.sina.com.cn private voID SendEmailAsync(string fromEmail,string fromPwd,string toEmail,string subject,string body,string emailType) { MailAddress addrFrom = new MailAddress(fromEmail,fromEmail); MailAddress addrTo = new MailAddress(toEmail,toEmail); MailMessage mm = new MailMessage(addrFrom,addrTo); mm.BodyEnCoding = EnCoding.UTF8; mm.IsBodyHTML = true; mm.Subject = subject; mm.Body = body; if (!string.IsNullOrEmpty(attfile)) { Attachment att = new Attachment(attfile,MediaTypenames.Application.Octet); Contentdisposition cd = att.Contentdisposition; cd.CreationDate = file.GetCreationTime(attfile); cd.ModificationDate = file.GetLastWriteTime(attfile); cd.ReadDate = file.GetLastAccesstime(attfile); mm.Attachments.Add(att);//添加附件 } NetworkCredential nc = new NetworkCredential(fromEmail,fromPwd); SmtpClIEnt smtp = new SmtpClIEnt(emailType); smtp.UseDefaultCredentials = false; smtp.Credentials = nc; smtp.EnableSsl = false; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.SendCompleted+=new SendCompletedEventHandler(smtp_SendCompleted); smtp.SendAsync(mm,"OK"); } voID smtp_SendCompleted(object sender,AsyncCompletedEventArgs e) { if (e.UserState.ToString() == "OK") MessageBox.Show("发送成功!","提示",MessageBoxbuttons.OK,MessageBoxIcon.information); }
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的C#异步发送Email代码全部内容,希望文章能够帮你解决C#异步发送Email代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)