zoukankan      html  css  js  c++  java
  • 发送电子邮件

    public class SimpleEmailHelper    

    {       

          private string _SmtpAdd; 

          private string _UserID;

          private string _UserPsw;

          public SimpleEmailHelper(string smtpAddress, string userID, string userPsw)  

           {    

                 _SmtpAdd = smtpAddress;   

              _UserID = userID;   

              _UserPsw = userPsw;   

          }

            public bool Send(string from, string to, string subject, string message,string cc)  

           {            

                   return Send(from, from, to, to, subject, message,cc);  

           }

            public bool Send(string from, string fromDisplay, string sendTo, string sendToDisplay,string subject, string message,string cc)      

          {

                bool ret = true;

                SmtpClient client = new SmtpClient();   

              client.Host = _SmtpAdd;//邮件服务器 比如 网易的是 smtp.163.COM        

            client.Port = 25;//端口号,也可不写       

           client.DeliveryMethod = SmtpDeliveryMethod.Network;//发送方式     

            client.Credentials = new NetworkCredential(_UserID, _UserPsw);//用户名和密码

                MailMessage myMessage = new MailMessage();        

         myMessage.Priority = MailPriority.Normal;//优先级     

            myMessage.From = new MailAddress(from, fromDisplay, Encoding.GetEncoding("gb2312"));   

              myMessage.To.Add(sendTo);   

              if (cc != "")       

          {          

           myMessage.CC.Add(cc);    

             }       

          myMessage.Subject = subject;//邮件主题    

             myMessage.SubjectEncoding = Encoding.GetEncoding("gb2312");   

              myMessage.IsBodyHtml = true;      

           myMessage.BodyEncoding = Encoding.GetEncoding("gb2312");     

            myMessage.Body = message;//正文     

            myMessage.Attachments.Add(new Attachment(@"C:\Users\lando\Desktop\Flex问题集结号.txt"));//加入附件。。。   

              client.Send(myMessage);//开始发送。       

          return ret;      

       }   

      }

    页面调用:

    SQ.FrameWork.SimpleEmailHelper emailHelper = new SQ.FrameWork.SimpleEmailHelper(stmpServerIpAddress, userId, psw);
    emailHelper.Send(from, distEmailAddress, TextBoxTopic.Text.Trim(),TextBoxContent.Text.Trim(),txtCCCleint.Text);
    ShowMessage("邮件发送成功。");
  • 相关阅读:
    PHP琐碎学习
    php输出echo、print、print_r、printf、sprintf、var_dump比较
    跨域
    react中配置路径别名
    react antd less(3.11.1) less-loader(5.0.0) webpack(4.42.0)设置antd的主题
    babel-plugin-import配置babel按需引入antd模块
    react配置less步骤
    react配置less后浏览器报错npm install @babel/core @babel/preset-env node_moduleswebpackhotdev-server.js: Cannot find module '@babel/helper-create-regexp-features-plugin'
    win10配置Java环境变量
    关于自定义组件的组件命名规范
  • 原文地址:https://www.cnblogs.com/fjzhang/p/2487500.html
Copyright © 2011-2022 走看看