C#發送郵件

來源:互聯網
上載者:User

標籤:地址   index   returns   priority   odi   logs   catch   from   郵件服務   

MailSend("公司", "發送郵箱", "發送密碼", "姓名", "接收郵箱", "說明", "詳細內容").ToString();public bool MailSend(string txtName, string txtEmail, string txtEmailPwd, string txtFormName, string txtFormEmail, string txtTitle,  string txtNeiRong)        {            string  smtpName = "smtp." + txtEmail.Substring(txtEmail.LastIndexOf("@") + 1);//伺服器            return NetMailSend(smtpName, txtEmail, txtEmailPwd, txtName, txtFormEmail, txtFormName, txtTitle, txtNeiRong, "");        }        /// <summary>        /// 發送郵件可帶附件,System.Net.Mail命名空間        /// </summary>        /// <param name="smtpName">郵件伺服器地址</param>        /// <param name="mailFrom">寄件者郵箱地址</param>        /// <param name="mailFromPwd">寄件者郵箱密碼</param>        /// <param name="fromUserName">寄件者名字</param>        /// <param name="mailTo">收件者郵箱地址</param>        /// <param name="toUserName">收件者名字</param>        /// <param name="mailSubject">郵件主題</param>        /// <param name="mailBody">郵件內容</param>         /// <param name="strFileName">附件名</param>        /// <returns>成功返回true,否則返回false</returns>        public bool NetMailSend(string smtpName, string mailFrom, string mailFromPwd, string fromUserName, string mailTo, string toUserName, string mailSubject, string mailBody, string strFileName)        {            bool isSucceed = false;//發送郵件是否成功            //郵件發送時請確認服務的殺毒軟體因素            System.Net.Mail.SmtpClient client;            client = new System.Net.Mail.SmtpClient(smtpName);            client.Timeout = 60000;            //client.UseDefaultCredentials = false;            client.UseDefaultCredentials = true;            client.Credentials = new System.Net.NetworkCredential(mailFrom, mailFromPwd);            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();            message.SubjectEncoding = System.Text.Encoding.UTF8;            message.BodyEncoding = System.Text.Encoding.UTF8;            message.From = new System.Net.Mail.MailAddress(mailFrom, fromUserName, System.Text.Encoding.UTF8);            message.To.Add(new System.Net.Mail.MailAddress(mailTo, toUserName, System.Text.Encoding.UTF8));            message.IsBodyHtml = true;            message.Subject = mailSubject;//郵件主題            message.Body = mailBody;//郵件內容            message.Priority = MailPriority.High;            //發送附件            if (!string.IsNullOrEmpty(strFileName))            {                Attachment data = new Attachment(strFileName);//附件                message.Attachments.Add(data);            }            try            {                client.Send(message);                isSucceed = true;            }            catch (Exception ex)            {                isSucceed = false;                //throw ex;            }            return isSucceed;        }

  

C#發送郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.