c# 两种发送邮件的方法

目录
  • 一、两种发送邮件的方法
  • 二、遇到的问题
  • 三、示例
    • System.Web.Mail
    • System.Net.Mail

一、两种发送邮件的方法

有用到两种方式发邮件,一种是用System.Web.Mail类,另一种是System.Net.Mail类。

System.Net.Mail是作为System.Web.Mail的替代存在的。

System.Web.Mail使用时会提示已过时,但目前任然可以正常使用。

二、遇到的问题

我在使用System.Net.Mail发邮件的时候遇到一个问题,如果是用的阿里云服务器,阿里云服务器把邮件的默认25端口给禁用掉了(为的是不让邮件泛滥),25端口被封,阿里云发送SMTP邮件失败。

在网上找了一些资料,主要有以下几种方法解决:

  1、在阿里云平台申请解封TCP 25 端口 (Outbound)

  2、更换端口号为465 或 587 ;

  3、服务器前缀加上 ssl://

  4、使用System.Web.Mail发送邮件

2和3我都试用无果,阿里云服务器还是发送邮件失败,最后使用System.Web.Mail发送成功,要是有别的更好的方法请大家告知,谢谢谢谢~~

三、示例

这里我把发邮件一些相关的参数配置在ini文件里(smt服务器、端口号、发件人邮箱、发件人密码、发件人昵称、接收人邮箱)

#region 读写本地IN文件

        public static string ReadIniFile(string iniFileName, string section, string key)
        {
            string strFileName = GetRootPath() + "\\" + iniFileName;

            if (!System.IO.File.Exists(strFileName))
            {
                FileStream fs = System.IO.File.Create(strFileName);
                fs.Close();
            }

            TWays.IniFile localIniFile = new TWays.IniFile(strFileName);

            return localIniFile.ReadInivalue(section, key);
        }

        public static void WriteIniFile(string iniFileName, string section, string key, string value)
        {
            string strFileName = GetRootPath() + "\\" + iniFileName;
            if (!System.IO.File.Exists(strFileName))
            {
                FileStream fs = System.IO.File.Create(strFileName);
                fs.Close();
            }

            TWays.IniFile localIniFile = new TWays.IniFile(strFileName);

            localIniFile.WriteInivalue(section, key, value);
        }

#endregion

        public const string MonitorLogFileName = "WmsImportSheetLog.Log";

        public const string MailSetIniFileName = "MailSet.ini";
        public const string MailSetSectionOption = "Option";
        public const string MailSetKeySmtpServer = "SmtpServer";//smtp服务器
        public const string MailSetKeySmtpPort = "SmtpPort";//端口号
        public const string MailSetKeySendAddr = "SendAddr";//发件人邮箱
        public const string MailSetKeySendPwd = "SendPwd";//发件人密码
        public const string MailSetKeySendUser = "SendUser";//发件人名称,可随意定义
        public const string MailSetKeyReceiAddr = "ReceiAddr";//收件人邮箱

//如果ini文件内没有内容就设置默认值
public void WriteMailSet()
        {
            string strFileName = BusiUtils.GetRootPath() + "\\" + Constant.MailSetIniFileName;

            if (!System.IO.File.Exists(strFileName))
            {
                BusiUtils.WriteIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySmtpServer, "smtp.163.com");
                BusiUtils.WriteIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySmtpPort, "465");
                BusiUtils.WriteIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySendAddr, "lala12121@163.com");

                string sendPwd = "lalala2017";
                sendPwd = TWays.Utils.EncryptString(sendPwd);

                BusiUtils.WriteIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySendPwd, sendPwd);
                BusiUtils.WriteIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySendUser, "系统管理员");
          //多个收件人用 ' ;' 号隔开
                BusiUtils.WriteIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeyReceiAddr, "1234@qq.com;5678@qq.com;2579@qq.com;");

            }
        }

System.Web.Mail

public bool Process()
        {
            bool boolReturn = false;

            try
            {
                string errorMsg = string.Empty;
                string title = "每日单据导入情况" + "-" + DateTime.Now.ToString("yyyy-MM -dd");
                string message = string.Empty;

                try
                {
                    WriteMailSet();

                    bool bl = true;
                    DataSet ds = DataAdapter.Query(SqlText.selectImportSheetErrorLog.ToUpper());

                    #region 

                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count <= 0)
                    {
                        message = "单据处理成功!";
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder();

                        sb.Append("以下为单据导入异常的消息:\r\n\r\n");

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            bl = false;
                            sb.Append("  任务编号:" + dr["TASK_CODE"].ToString() + ",\t");
                            sb.Append("  任务名称:" + dr["TASK_NAME"].ToString() + ",\t");
                            sb.Append("  日志消息:" + dr["MEMO"].ToString());
                            sb.Append("\r\n");
                        }
                        message = sb.ToString();
                    }

                    #endregion

                    if (bl)
                    {
                        title = "[成功]" + title;
                    }
                }
                catch (Exception Ex)
                {
                    message = Ex.Message;

                    errorMsg = "邮件发送失败!错误信息:" + message;

                    message = "Error:" + Ex.Message;

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);

                    return boolReturn;
                }

                #region 发送邮件

                try
                {

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, "发送" + title + "开始\r\n", true);

                    bool result = Monitor(title, message, "", "");

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, "发送" + title + "结束\r\n", true);

                }
                catch (Exception Ex)
                {
                    errorMsg = "邮件发送失败!错误信息:" + Ex.Message;

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);

                    return boolReturn;
                }
                #endregion

                Result = "Succeed";
                boolReturn = true;
            }
            catch (Exception ex)
            {
                Result = ex.Message;
            }

            return boolReturn;
        }

        private bool Monitor(string title, string message, string fileName, string shortFileName)
        {
            string smtpServer = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySmtpServer);
            string smtpPort = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySmtpPort);
            string sendAddr = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySendAddr);
            string sendPwd = Utils.DecryptString(BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySendPwd));
            string receiAddr = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeyReceiAddr);

            string errorMsg = string.Empty;

            try
            {
                System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage();
                //邮件主题
                mmsg.Subject = title;
                //mmsg.BodyFormat = System.Web.Mail.MailFormat.Html;
                //邮件正文
                mmsg.Body = message;
                //正文编码
                mmsg.BodyEncoding = Encoding.UTF8;
                //优先级
                mmsg.Priority = System.Web.Mail.MailPriority.High;

                System.Web.Mail.MailAttachment data = null;
                //if (SUpFile != "")
                //{
                //    SUpFile = HttpContext.Current.Server.MapPath(SUpFile);//获得附件在本地地址
                //    System.Web.Mail.MailAttachment attachment = new System.Web.Mail.MailAttachment(SUpFile); //create the attachment
                //    mmsg.Attachments.Add(attachment); //add the attachment
                //}
                //发件者邮箱地址
                mmsg.From = string.Format("\"{0}\"<{1}>", "方予系统管理员", sendAddr);

                //收件人收箱地址
                mmsg.To = receiAddr;
                mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                //用户名
                mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sendAddr);
                //密码 不是邮箱登陆密码 而是邮箱设置POP3/SMTP 时生成的第三方客户端授权码
                mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sendPwd);
                //端口
                mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", smtpPort);
                //使用SSL
                mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
                //Smtp服务器
                System.Web.Mail.SmtpMail.SmtpServer = smtpServer;

                System.Web.Mail.SmtpMail.Send(mmsg);

                System.Threading.Thread.Sleep(20000);

            }
            catch (Exception Ex)
            {
                errorMsg = "邮件发送失败!错误信息:" + Ex.Message;
                TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);
                return false;
            }

            return true;
        }

System.Net.Mail

SmtpClient SmtpClient = null;   //设置SMTP协议
MailAddress MailAddress_from = null; //设置发信人地址  当然还需要密码
MailAddress MailAddress_to = null;  //设置收信人地址  不需要密码
MailMessage MailMessage_Mai = null;
FileStream FileStream_my = null; //附件文件流

public bool Process()
        {
            bool boolReturn = false;

            try
            {
                string errorMsg = string.Empty;
                string title = "每日单据导入情况" + "-" + DateTime.Now.ToString("yyyy-MM-dd");
                string message = string.Empty;

                try
                {
                    WriteMailSet();

                    bool bl = true;
                    DataSet ds = DataAdapter.Query(SqlText.selectImportSheetErrorLog.ToUpper());

                    #region 

                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count <= 0)
                    {
                        message = "单据导入成功!";
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder();

                        sb.Append("以下为单据导入异常的消息:\r\n\r\n");

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            bl = false;
                            sb.Append("  任务编号:" + dr["TASK_CODE"].ToString() + ",\t");
                            sb.Append("  任务名称:" + dr["TASK_NAME"].ToString() + ",\t");
                            sb.Append("  日志消息:" + dr["MEMO"].ToString());
                            sb.Append("\r\n");
                        }
                        message = sb.ToString();
                    }

                    #endregion

                    if (bl)
                    {
                        title = "[成功]" + title;
                    }
                }
                catch (Exception Ex)
                {
                    message = Ex.Message;

                    errorMsg = "邮件发送失败!错误信息:" + message;

                    message = "Error:" + Ex.Message;

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);

                    return boolReturn;
                }

                #region 发送邮件

                try
                {

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, "发送" + title + "开始\r\n", true);

                    bool result = Monitor(title, message, "", "");

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, "发送" + title + "结束\r\n", true);

                }
                catch (Exception Ex)
                {
                    errorMsg = "邮件发送失败!错误信息:" + Ex.Message;

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);

                    return boolReturn;
                }
                #endregion

                Result = "Succeed";
                boolReturn = true;
            }
            catch (Exception ex)
            {
                Result = ex.Message;
            }

            return boolReturn;
        }

        private bool Monitor(string title, string message, string fileName, string shortFileName)
        {
            string smtpServer = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySmtpServer);
            string smtpPort = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySmtpPort);
            string sendAddr = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySendAddr);
            string sendPwd = Utils.DecryptString(BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySendPwd));
            string receiAddr = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeyReceiAddr);

            string errorMsg = string.Empty;

            try
            {
                //初始化Smtp服务器信息
                setSmtpClient(smtpServer, Convert.ToInt32(smtpPort));
            }
            catch (Exception Ex)
            {
                errorMsg = "邮件发送失败,请确定SMTP服务名是否正确!错误信息:" + Ex.Message;
                TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);
                return false;
            }
            try
            {
                //验证发件邮箱地址和密码
                setAddressform(sendAddr, sendPwd);
            }
            catch (Exception Ex)
            {
                errorMsg = "邮件发送失败,请确定发件邮箱地址和密码的正确性!错误信息:" + Ex.Message;
                TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);
                return false;
            }
            try
            {
                MailMessage_Mai = null;
                MailMessage_Mai = new MailMessage();
                //清空历史发送信息 以防发送时收件人收到的错误信息(收件人列表会不断重复)
                MailMessage_Mai.To.Clear();
                string[] recAddress = receiAddr.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                //添加收件人邮箱地址
                for (int i = 0; i < recAddress.Length; i++)
                {
                    MailAddress_to = new MailAddress(recAddress[i]);
                    MailMessage_Mai.To.Add(MailAddress_to);
                }

                //发件人邮箱
                MailMessage_Mai.From = MailAddress_from;
                //邮件主题
                MailMessage_Mai.Subject = title;
                MailMessage_Mai.SubjectEncoding = System.Text.Encoding.UTF8;
                //邮件正文
                MailMessage_Mai.Body = message;
                MailMessage_Mai.BodyEncoding = System.Text.Encoding.UTF8;

                //清空历史附件  以防附件重复发送
                //MailMessage_Mai.Attachments.Clear();
                //FileStream_my = new FileStream(fileName, FileMode.Open);
                //string name = FileStream_my.Name;
                ////添加附件
                //MailMessage_Mai.Attachments.Add(new Attachment(FileStream_my, shortFileName));

                //注册邮件发送完毕后的处理事件
                SmtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);

                //开始发送邮件
                SmtpClient.SendAsync(MailMessage_Mai, "000000000");

                System.Threading.Thread.Sleep(30000);
            }
            catch (Exception Ex)
            {
                errorMsg = "邮件发送失败!错误信息:" + Ex.Message;
                TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);
                return false;
            }

            return true;
        }

        #region 设置Smtp服务器信息

        /// <summary>
        /// 设置Smtp服务器信息
        /// </summary>
        /// <param name="ServerName">SMTP服务名</param>
        /// <param name="Port">端口号</param>
        private void setSmtpClient(string ServerHost, int Port)
        {
            SmtpClient = new SmtpClient();
            SmtpClient.Host = ServerHost;//指定SMTP服务名  例如QQ邮箱为 smtp.qq.com 新浪cn邮箱为 smtp.sina.cn等
            SmtpClient.Port = Port; //指定端口号
            SmtpClient.Timeout = 5;  //超时时间
            SmtpClient.EnableSsl = true; //指定 SmtpClient 使用安全套接字层 (SSL) 加密连接
        }

        #endregion

        #region 验证发件人信息

        /// <summary>
        /// 验证发件人信息
        /// </summary>
        /// <param name="MailAddress">发件邮箱地址</param>
        /// <param name="MailPwd">邮箱密码</param>
        private void setAddressform(string MailAddress, string MailPwd)
        {
            string sendUser = BusiUtils.ReadIniFile(Constant.MailSetIniFileName, Constant.MailSetSectionOption, Constant.MailSetKeySendUser);

            //创建服务器认证
            NetworkCredential NetworkCredential_my = new NetworkCredential(MailAddress, MailPwd);
            //实例化发件人地址
            MailAddress_from = new System.Net.Mail.MailAddress(MailAddress, sendUser, Encoding.BigEndianUnicode);
            //指定发件人信息  包括邮箱地址和邮箱密码
            SmtpClient.Credentials = new System.Net.NetworkCredential(MailAddress_from.Address, MailPwd);
        }

        #endregion

        #region 发送邮件后所处理的函数

        private void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
        {
            string errorMsg = string.Empty;
            try
            {
                if (e.Cancelled)
                {
                    errorMsg = "发送已取消!";

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);
                }
                if (e.Error != null)
                {
                    errorMsg = "邮件发送失败!1错误信息:" + e.Error.Message;

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);
                }
                else
                {
                    errorMsg = "恭喜,邮件成功发出!";

                    TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);
                }

                if (FileStream_my != null)
                {
                    FileStream_my.Close();
                }
            }
            catch (Exception Ex)
            {
                errorMsg = "邮件发送失败!2错误信息:" + Ex.Message;

                TWays.Core.Loger.LogMessage(BusiUtils.GetRootPath() + "\\" + Constant.MonitorLogFileName, errorMsg + "\r\n", true);
            }
        }

        #endregion

以上就是c# 两种发送邮件的方法的详细内容,更多关于c# 发送邮件的资料请关注我们其它相关文章!

(0)

相关推荐

  • C# Email邮件发送功能 找回或重置密码功能

    最近根据公司需求,写个邮件发送.这里面的传入的地址信息的参数都是经过加密的,主要是保证用户信息的安全. using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; using System.Net.Mail; using System.Text; using System.Web; namespace CalslNum.Helper

  • C#实现QQ邮箱发送邮件

    闲着蛋疼.计划着改善公司的邮件服务.怎料公司网络封闭的太厉害了.我只能在家里利用开放点的网络来测试发送邮件: 利用qq邮箱发送到公司的企业邮箱上: 前提准备,登陆qq邮箱开启stmp服务.不开启的话没法通过代码登陆到你的邮箱: 查询腾讯qq邮箱的smtp主机地址为:smtp.qq.com  端口是587,或者465 using System; using System.Collections.Generic; using System.Linq; using System.Text; using

  • C#使用System.Net邮件发送功能踩过的坑

    1.EazyEmail邮件发送类库 Net 类库自带了邮件发送功能.笔者对该类库,从使用的角度进行了二次封装,nuget上可搜索EazyEmail,注入容器时通过委托来获得邮箱服务器的配置地址以及发送地址直接调用send方法即可. 容器注入代码.这里定义的委托,每次发送之前可以去数据库拿邮箱配置数据跟发送账户,笔者自己用的时候是通过Redis缓存 存取数据,因为像断网断电这种可能是批量出现的,需要批量发送告警邮件,所以放Redis里,然后Redis通过rdb功能设置每秒每个键变化就持久化的策略,

  • C#使用系统方法发送异步邮件完整实例

    本文实例讲述了C#使用系统方法发送异步邮件.分享给大家供大家参考,具体如下: 项目背景: 最近在对几年前的一个项目进行重构,发现发送邮件功能需要一定的时间来处理,而由于发送是同步的因此导致在发送邮件时无法执行后续的操作 实际上发送邮件后只需要将发送结果写入系统日志即可对其他业务没有任何影响,因此决定将发送邮件操作更改为异步的 由于使用的是C#的邮件类库,而C#本身已经提供了异步发送的功能即只需要将Send方法更改为SendAsync即可,更改方法名并不难但发送后再写入日志就有点难了 因为项目中发

  • C#结合SMTP实现邮件报警通知的实现示例

    写在前面 C#是微软推出的一门面向对象的通用型编程语言,它除了可以开发PC软件.网站(借助http://ASP.NET)和APP(基于 Windows Phone),还能作为游戏脚本,编写游戏逻辑.SMTP是一种提供可靠且有效的电子邮件传输的协议,是建立在FTP文件传输服务上的一种邮件服务,主要用于系统之间的邮件信息传递,并提供有关来信的通知.今天主要跟大家分享一下如何通过C#结合SMTP来实现报警通知. 1 整体思路 C#结合SMTP实现邮件报警通知,经过分析,我们需要解决以下两个问题: 第一

  • 使用c#+IMap实现收取163邮件

    最近我要做一个爬虫.这个爬虫需要如下几个步骤: 1 填写注册内容(需要邮箱注册) 2 过拖拽验证码(geetest) 3 注册成功会给邮箱发一封确认邮箱 4 点击确认邮箱中的链接 完成注册 我这里就采用163邮箱注册. 邮箱协议有 pop3 和 imap 和 smtp 我试了pop3  不能够筛选邮件 例如筛选未读 和 发件人这2个条件 所以放弃用pop3 imap协议是支持的. 我就找了一个开源的第三方lib:S22.Imap 用法很简单: public void Test163() { va

  • c#使用IMap收取163邮件的方法示例

    前言 IMAP全称是Internet Mail Access Protocol,即交互式邮件存取协议,它是跟POP3类似邮件访问标准协议之一.不同的是,开启了IMAP后,您在电子邮件客户端收取的邮件仍然保留在服务器上,同时在客户端上的操作都会反馈到服务器上,如:删除邮件,标记已读等,服务器上的邮件也会做相应的动作.所以无论从浏览器登录邮箱或者客户端软件登录邮箱,看到的邮件以及状态都是一致的. 最近我要做一个爬虫.这个爬虫需要如下几个步骤: 1 填写注册内容(需要邮箱注册) 2 过拖拽验证码(ge

  • c# 实现发送邮件的功能

    微软已经为我们准备好了现成的工具类供我们调用: MailMessage //邮件信息类 SmtpClient //邮件发送类 首先需要在项目的类文件中引用以下命名空间: using System.Net; using System.Net.Mail; 然后直接上封装好的代码: /// <summary> /// 发送邮件方法 /// </summary> /// <param name="mailTo">接收人邮件</param> ///

  • C# 服务器发送邮件失败实例分析

    错误展示: 我在本地是可以发送的但部署到服务器上后就不能发送了.SMTP服务是开了的. 报错: "{"success":false,"message":"错误System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.163.com' 分析: 邮件

  • c# 实现发送邮件到指定邮箱

    很多小伙伴对于[程序发送邮件]不明觉厉的同时又羡慕嫉妒恨,其实发送邮件是一个很常用的功能, 我们这里就简单做一个发送邮箱的案例. PS:案例使用qq邮箱,当然,也可以使用其他邮箱,只要替换邮箱关键字即可,下面案例已做标注. 首先,我们需要一个[当前发件授权码],这个码需要登录发件箱里面进行开启,我们先开启一下. 1.登录发件箱的邮箱,进入[设置] 2.点击[账户] 3.下滑找到POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务,点击开启,根据提示操作完成后得到一个授

  • C# SMTP发送邮件的示例

    在程序开发中通常有推送消息的需求,通常为短信服务,邮件,电话提醒. 短信及电话提醒通常需要向运营商购买服务调用接口,比较麻烦.邮件信息推送也是不错的选择,下面使用C#实现SMTP发送邮件 复制代码/// <summary> /// 发送邮件 /// </summary> /// <param name="M">发件内容</param> public static void LocalHostSend(SendMail M) { try {

随机推荐