Example #1
0
        public void CreateMail(ConfigMail mail)
        {
            Mail      = new MailMessage();
            Mail.From = new MailAddress(mail.From, mail.FromName, System.Text.Encoding.UTF8);

            //Mail.From = new MailAddress("*****@*****.**", "来自模具系统的邮件2", System.Text.Encoding.UTF8);

            if (mail.To != null)
            {
                //收件人
                foreach (var t in mail.To)
                {
                    Mail.To.Add(t);
                }
            }
            if (mail.CC != null)
            {
                //抄送人
                foreach (var t in mail.CC)
                {
                    Mail.CC.Add(t);
                }
            }
            if (mail.Bcc != null)
            {
                //密送人
                foreach (var t in mail.Bcc)
                {
                    Mail.Bcc.Add(t);
                }
            }
            Mail.Subject         = mail.Subject;
            Mail.Body            = mail.Body;
            Mail.IsBodyHtml      = true; // true;
            Mail.BodyEncoding    = System.Text.Encoding.UTF8;
            Mail.SubjectEncoding = System.Text.Encoding.UTF8;

            //msg.IsBodyHtml = true;
            //msg.Priority = MailPriority.High;//优先级
        }
Example #2
0
        public void CreateMultiMail(ConfigMail mail)
        {
            CreateMail(mail);

            if (mail.Resources != null && mail.Resources.Length > 0)  //不启用这段
            {
                Mail.AlternateViews.Add(AlternateView.CreateAlternateViewFromString("If you see this message, it means that your mail client does not support html.", Encoding.UTF8, "text/plain"));
                var html = AlternateView.CreateAlternateViewFromString(mail.Body, Encoding.UTF8, "text/html");
                foreach (string resource in mail.Resources)
                {
                    var image = new LinkedResource(resource, "image/jpeg");
                    image.ContentId = Convert.ToBase64String(Encoding.Default.GetBytes(Path.GetFileName(resource)));
                    html.LinkedResources.Add(image);
                }
                Mail.AlternateViews.Add(html);
            }

            foreach (var attachment in mail.Attachments)
            {
                Mail.Attachments.Add(new Attachment(attachment));
            }
        }
Example #3
0
 public UseNetMail(ConfigMail mail, ConfigHost host)
 {
     //构造函数,初始化对象
     cMail = mail;
     cHost = host;
 }