.NET发送邮件的方法
整理一下,在.NET中发送邮件的一个方法,代码如下:
public static string Net_Email(string strSendto, string strCC, string strBCC, string strMailContent, string strMailTitle, string[] strMailAttachMent, string strMailFormat, string strServiceTeam)
{
try
{
MailMessage mMail = new MailMessage();
using (mMail)
{
strMailContent = strMailContent.Replace("<br>\n", "<br>");
string[] ListTo = strSendto.Split(';');
for (int i = ; i < ListTo.Length; i++)
{
if (ListTo[i].Equals("")) continue;
mMail.To.Add(ListTo[i]);
}
string[] ListCC = strCC.Split(';');
for (int i = ; i < ListCC.Length; i++)
{
if (ListCC[i].Equals("")) continue;
mMail.CC.Add(ListCC[i]);
}
string[] ListBCC = strBCC.Split(';');
for (int i = ; i < ListBCC.Length; i++)
{
if (ListBCC[i].Equals("")) continue;
mMail.Bcc.Add(ListBCC[i]);
}
string[] strMailFrom = strServiceTeam.Split(';');
mMail.From = strMailFrom[].IndexOf("@", StringComparison.Ordinal) > ? new MailAddress(strMailFrom[]) : new MailAddress("xxxxx@xxx.com.cn");
mMail.Body = strMailContent;
mMail.Subject = strMailTitle;
mMail.IsBodyHtml = strMailFormat == "";
for (int i = ; i < strMailAttachMent.Length; i++)
{
string strFJ = strMailAttachMent[i] + "";
if (strFJ.Length > )
{
mMail.Attachments.Add(new Attachment(strFJ));
}
}
SmtpClient smtp = new SmtpClient();
smtp.Host = "10.10.10.10";
smtp.Credentials = new NetworkCredential("emailcn", "");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mMail);
return "";
}
}
catch (Exception ex)
{
return ex.Message;
}
}
调用方式:
组装邮件内容的时候,是调用一个html模板,将其中的标签内容进行替换
var strFileCn = File.ReadFile(MapPath("order_model.html"), "utf-8");
strFileCn = strFileCn.Replace("#orderid#", orders.orderid);
strFileCn = strFileCn.Replace("#username#", orders.username);
var att = new string[1];
att[0] = "";
Net_Email(strsendto, strcc, "", strFileCn, "商品订购单Order sheet.",att, "", "")
.NET发送邮件的方法的更多相关文章
- linux利用sendmail发送邮件的方法
Linux利用sendmail发送邮件, 方法1 安装sendmail即可使用, mail -s "test" user@sohu.com bin/mail会默认使用本地sendm ...
- 执行发送邮件Send方法时,报错:邮箱不可用。 服务器响应为: 5.7.1 Unable to relay for xxx@xxx.com
.net代码在执行发送邮件Send方法时,往往出现这个的报错: 邮箱不可用. 服务器响应为: 5.7.1 Unable to relay for xxx@xxx.com 这个问题应该是smtp的设置问 ...
- asp.net基于windows服务实现定时发送邮件的方法
本文实例讲述了asp.net基于windows服务实现定时发送邮件的方法.分享给大家供大家参考,具体如下: //定义组件 private System.Timers.Timer time; publi ...
- java发送邮件基础方法(另附部分主流邮箱服务器地址、端口及设置方法)
java发送邮件基础方法,可通过重载简化参数 import java.io.File; import java.io.UnsupportedEncodingException; import java ...
- 【原】移动web页面给用户发送邮件的方法 (邮件含文本、图片、链接)
微信商户通有这么一个需求,用户打开H5页面后,引导用户到电脑下载设计资源包,由于各种内部原因,被告知无后台资源支持,自己折腾了一段时间找了下面2个办法,简单做下笔记. 使用mailto功能,让用户自己 ...
- 移动web页面给用户发送邮件的方法
微信商户通有这么一个需求,用户打开H5页面后,引导用户到电脑下载设计资源包,由于各种内部原因,被告知无后台资源支持,自己折腾了一段时间找了下面2个办法,简单做下笔记. 使用mailto功能,让用户自己 ...
- Laravel中利用队列发送邮件的方法示例
https://www.jb51.net/article/121647.htm 本文主要给大家介绍了关于Laravel中队列发送邮件的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的 ...
- PHPMailer实现发送邮件的方法介绍
来自: https://www.php.cn/php-weizijiaocheng-408762.html PHPmailer请在github下载,或者直接百度,也不难,虽然PHPmailer里面一大 ...
- thinkphp5.1发送邮件的方法
1.安装插件 composer require phpmailer/phpmailer 2.application下的common.php文件里加上一下代码,可自己根据需求稍加修改,我用的是验证码 u ...
随机推荐
- 问题; No label views point to this text field with an android:labelFor="@+id/@+id/editTextNumber1" attribute
设置完EditText的ID后老是报一个警告. 解决方法: 需要在EditText属性中添加inputType和labelFor两个属性.其中labelFor属性的值与id值相同即可
- oracle 查询列表中选取其中一行
select k.SAL from (select SAL,rownum rn from (select SAL from SCOTT.EMP where MGR = 7698 order by SA ...
- nginx 刷新显示404
HTML5 History 模式 vue-router 默认 hash 模式 —— 使用 URL 的 hash 来模拟一个完整的 URL,于是当 URL 改变时,页面不会重新加载. 如果不想要很丑的 ...
- as3.0加载swf并控制
私人QQ 280841609 var myload:Loader=new Loader(); var url:URLRequest=new URLRequest("1.swf"); ...
- 解决libc.so.6: version `GLIBC_2.14' not found问题
1.命令检查系统glibc支持的版本: strings /lib64/libc.so.6 |grep GLIBC_ 如果没有2.14或者其他版本的,需要下载安装 2.下载地址:http://pan.b ...
- 51nod 1163 最高的奖励
链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励 基准时间限制:1 秒 空间限制:13 ...
- 字符串 String 格式化 format
String str=String.format("Hi,%s", "王力"); 保留两位数的整数: String str=String.format(&quo ...
- this.class.getClassLoader().getResourceAsStream与this.class.getResourceAsStream 文件地址获取
本文部分转自:http://xixinfei.iteye.com/blog/1256291 this.getClass().getClassLoader().getResource("tem ...
- python的定时任务模块--schedule
首先先安装一下模块 下面我们简单的学习一下schedule模块 先简单的看个示例 import schedule def test(*args,**kwargs): print("hello ...
- Python 安装pyautogui
在Python中使用PyAutoGui模拟键盘和鼠标操作 一.系统环境 操作系统:win10 64位 Python版本:Python 3.7.0 二.安装参考 1.使用pip进行安装,pip inst ...