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

    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;
            }
    

      

  • 相关阅读:
    Creating and Using Static Libraries for iPhone using Xcode 4.3
    Build fat static library (device + simulator) using Xcode and SDK 4+
    How to safely shut down a loading UIWebView in viewWillDisappear?
    处理iOS设备的屏幕旋转
    Instruments Tutorial for iOS: How To Debug Memory Leaks【转】
    自定义UINavigationBar的背景【转】
    iOS编程——Objective-C KVO/KVC机制[转]
    ios PNG Crush error (PNG图片错误)
    实现自定义延迟加载的滚动视图
    Linux添加或修改ssh端口
  • 原文地址:https://www.cnblogs.com/XuPengLB/p/6396822.html
Copyright © 2011-2022 走看看