Exemple #1
0
 /// <summary>
 /// 发送邮件
 /// MailMsg msg= new MailMsg();
 /// msg.Subject="";...
 /// Smtp smtp = new Smtp("mail.OpenSmtp.com", 25);
 /// smtp.Username="";
 /// smtp.Password="";
 /// smtp.SendMail(msg);
 /// </summary>
 /// <param name="msg"></param>
 public void SendMail(MailMsg msg)
 {
     System.Net.Mail.MailAddress from =
         new System.Net.Mail.MailAddress(msg.From);
     System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress(msg.To);
     //System.Net.Mail.MailAddress copyTo = new System.Net.Mail.MailAddress(model.CopyTo);
     System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
     message.Subject         = msg.Subject;
     message.Body            = msg.Body;
     message.SubjectEncoding = System.Text.Encoding.UTF8;
     message.BodyEncoding    = System.Text.Encoding.UTF8;
     if (msg.AttachmentList != null && msg.AttachmentList.Count > 0)
     {
         foreach (String attachment in msg.AttachmentList)
         {
             if (File.Exists(attachment))
             {
                 System.Net.Mail.Attachment attachFile =
                     new System.Net.Mail.Attachment(attachment);
                 message.Attachments.Add(attachFile);
             }
         }
     }
     System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(this.Host);
     client.UseDefaultCredentials = false;
     client.Credentials           = new System.Net.NetworkCredential(this.Username, this.Password);
     client.DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network;
     client.Send(message);
     message.Dispose();
 }
Exemple #2
0
        /// <summary>
        /// 发送邮件
        /// Smtp smtp = new Smtp("mail.OpenSmtp.com", 25);
        /// smtp.Username="";
        /// smtp.Password="";
        /// smtp.SendMail("*****@*****.**", "*****@*****.**", "Hi", "Hello Joe Smith");
        /// </summary>
        /// <param name="from">发送邮件地址</param>
        /// <param name="to">接收邮件地址</param>
        /// <param name="subject">邮件主题</param>
        /// <param name="body">邮件内容</param>
        public void SendMail(string from, string to, string subject, string body)
        {
            MailMsg msg = new MailMsg();

            msg.Subject = subject;
            msg.Body    = body;
            msg.From    = from;
            msg.To      = to;
            SendMail(msg);
        }
Exemple #3
0
        /// <summary>
        /// 发送邮件
        /// Smtp smtp = new Smtp("mail.OpenSmtp.com", 25);
        /// smtp.Username="";
        /// smtp.Password="";
        /// smtp.SendMail("*****@*****.**", "*****@*****.**", "Hi", "Hello Joe Smith",FileInfoList);
        /// </summary>
        /// <param name="from">发送邮件地址</param>
        /// <param name="to">接收邮件地址</param>
        /// <param name="subject">邮件主题</param>
        /// <param name="body">邮件内容</param>
        /// <param name="attList">邮件附件</param>
        public void SendMail(string from, string to, string subject, string body, List <String> attList)
        {
            MailMsg msg = new MailMsg();

            msg.Subject        = subject;
            msg.Body           = body;
            msg.From           = from;
            msg.To             = to;
            msg.AttachmentList = attList;
            SendMail(msg);
        }
Exemple #4
0
        /// <summary>
        /// 发送邮件
        /// Smtp smtp = new Smtp();
        /// smtp.SendMail("*****@*****.**","*****@*****.**","Test","这是一封测试邮件","FileInfo","smtp.163.com",25,"zy0412326","123456");
        /// </summary>
        /// <param name="from">发送邮件地址</param>
        /// <param name="to">接收邮件地址</param>
        /// <param name="subject">邮件主题</param>
        /// <param name="body">邮件内容</param>
        /// <param name="attList">邮件附件</param>
        /// <param name="host">SMTP服务器</param>
        /// <param name="port">端口号</param>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        public void SendMail(string from, string to, string subject, string body,
                             List <String> attList, string host, int port, string username, string password)
        {
            MailMsg msg = new MailMsg();

            msg.Subject        = subject;
            msg.Body           = body;
            msg.From           = from;
            msg.To             = to;
            msg.AttachmentList = attList;

            this.Host     = host;
            this.Port     = port;
            this.Username = username;
            this.Password = password;
            SendMail(msg);
        }
Exemple #5
0
 /// <summary>
 /// 发送邮件
 /// </summary>
 /// <param name="msg">邮件对象</param>
 /// <param name="host">SMTP服务器</param>
 /// <param name="port">端口号</param>
 public void SendMail(MailMsg msg, string host, int port)
 {
     this.Host = host;
     this.Port = port;
     SendMail(msg);
 }