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

    using System;
    using System.Web;
    
    namespace HuaTong.General.Utility
    {
        /// <summary>
        /// 邮件发送
        /// </summary>
        public class EmailHelper
        {
            string MailAddress = "";
            string MailName = "";
            string MailHost = "";
            string MailPassword = "";
    
            public EmailHelper(string mailAddress, string mailName, string mailHost, string mailPassword)
            {
                MailAddress = mailAddress;
                MailName = mailName;
                MailHost = mailHost;
                MailPassword = mailPassword;
            }
    
            /// <summary>
            /// 发送邮件
            /// </summary>
            public bool SendMail(string subject, string body, string to, bool Ishtml)
            {
                using (System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage())
                {
                    msg.To.Add(to);
                    msg.From = new System.Net.Mail.MailAddress(MailAddress, MailName, System.Text.Encoding.UTF8);
                    msg.Subject = subject;//邮件标题             
                    msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 
                    msg.Body = body;//邮件内容 
                    msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 
                    msg.IsBodyHtml = Ishtml;//是否是HTML邮件 
                    msg.Priority = System.Net.Mail.MailPriority.Normal;//邮件优先级
                    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                    client.Credentials = new System.Net.NetworkCredential(MailAddress, MailPassword);
                    client.Host = MailHost;
                    object userState = msg;
                    try
                    {
                        client.Send(msg);
                        return true;
                    }
                    catch
                    {
                        return false;
                    }
                }
            }
        }
    }
  • 相关阅读:
    使用webService时,gsoap数据类型注意事项
    DB:HQL
    云:政务云
    专业词汇:电子政务(政府运作模式)
    Java-框架-Dubbo:Dubbo
    架构-Java-Netty:Netty框架
    职业-企业家:企业家
    信息服务:高考填报志愿综合参考系统
    Java-Class-FC:java.time.Duration.java
    Java-Class-@I:java.annotation.Resource.java
  • 原文地址:https://www.cnblogs.com/password1/p/5870701.html
Copyright © 2011-2022 走看看