| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Mail;
- using System.Text;
- namespace Muchinfo.PC.Common.Helpers
- {
- public class MailSendHelper
- {
- /// <summary>
- /// 客户端发送邮件
- /// </summary>
- /// <param name="ToAddress">收件人邮箱地址,多个收件人用;隔开</param>
- /// <param name="Address">发送人邮箱地址</param>
- /// <param name="Password">发送人邮箱密码</param>
- /// <param name="Host">服务器</param>
- /// <param name="port">端口</param>
- /// <param name="DisplayName">默认发送人名称</param>
- /// <param name="Title">主题</param>
- /// <param name="Content">内容</param>
- /// <param name="Attachments">附件地址,多个附件用;隔开</param>
- public static bool MailSend(
- string ToAddress,
- string Address,
- string Password,
- string Host,
- int port,
- string DisplayName,
- string Title,
- string Content,
- string Attachments,
- out string Error)
- {
- Error = "";
- char[] ch = new char[] { ';' };
- try
- {
- MailMessage ms = new MailMessage();
- foreach (string str in ToAddress.Split(ch))
- {
- ms.To.Add(str);
- }
- ms.From = new MailAddress(Address, DisplayName, System.Text.Encoding.UTF8);
- ms.Priority = MailPriority.High;
- ms.Subject = Title;
- ms.SubjectEncoding = System.Text.Encoding.UTF8;
- ms.Body = Content;
- if (!string.IsNullOrWhiteSpace(Attachments))
- {
- foreach (string str in Attachments.Split(ch))
- {
- Attachment ath = new Attachment(str);
- ms.Attachments.Add(ath);
- }
- }
- ms.BodyEncoding = System.Text.Encoding.UTF8;
- ms.IsBodyHtml = false;
- SmtpClient sc = new SmtpClient();
- sc.Credentials = new System.Net.NetworkCredential(Address, Password);
- sc.Host = Host;
- sc.Port = port;
- sc.Send(ms);
- return true;
- }
- catch (Exception ex)
- {
- Error = ex.Message;
- return false;
- }
- }
- }
- }
|