• c# 发邮件


    /// <param name="smtp">发件服务器</param>
           /// <param name="pwd">发件人密码</param>
           /// <param name="sendMail">发件人邮箱</param>
           /// <param name="recipientMail">收件人邮箱</param>
           /// <param name="sendUsername">发送人姓名</param>
           /// <param name="recipientUsername">收件人姓名</param>
           /// <param name="Subject">邮件主题</param>
           /// <param name="Body">邮件内容</param>
            /// <returns>是否发送成功</returns>
           public string sendMail(string smtp,string pwd,string sendMail,string recipientMail,string sendUsername,string recipientUsername,string Subject,string Body)
           {
               try
               {
                   System.Net.Mail.SmtpClient client = new SmtpClient(smtp);//初始化服务器

                   client.UseDefaultCredentials = false;
                   client.Credentials = new System.Net.NetworkCredential(sendMail, pwd);//发送人的账户,密码
                   client.DeliveryMethod = SmtpDeliveryMethod.Network;//指定如何处理待发邮件

                   MailAddress addressFrom = new MailAddress(sendMail, sendUsername); //发件人地址,姓名
                   MailAddress addressTo = new MailAddress(recipientMail, recipientUsername);//收件人地址,姓名


                   System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(addressFrom, addressTo); //发信

                   message.Sender = new MailAddress(sendMail);
                   message.Subject = Subject;
                   message.Body = Body;
                   message.BodyEncoding = System.Text.Encoding.UTF8;
                   message.IsBodyHtml = true;

                   client.Send(message);
                   return "true";
               }
               catch(Exception ex)
               {
                   return (ex.Message);
               }
           }

  • 相关阅读:
    我的浏览器和常用扩展
    Win10安装.Net Framework4.7及更高版本
    压缩和解压工具bandizip
    Oracle trunc()函数的用法
    Oracle 中 decode 函数用法
    Js/Jquery获取iframe中的元素 在Iframe中获取父窗体的元素方法
    String literal is not properly closed by a double-quote eclipse
    linux 启动 Oracle 实例
    查询当前Oracle数据库的实例
    sqlplus 执行 sql 文件
  • 原文地址:https://www.cnblogs.com/xuchi/p/2288663.html
Copyright © 2020-2023  润新知