首页 > 代码库 > C#发送邮件
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 = http://www.mamicode.com/new Attachment(strFileName);//附件>
C#发送邮件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。