public static void mailadd(string mailto, string mailsubject, string mailbody, string attech)//创建Mail,填入发送人,主题,內容 { { MailMessage mlMsg = new MailMessage(); //处理多个收件人 string[] toArray = mailto.Split(','); foreach (string i in toArray) { mlMsg.To.Add(new MailAddress(i)); } mlMsg.Subject = mailsubject; mlMsg.Body = mailbody; mlMsg.IsBodyHtml = true; mlMsg.From = new MailAddress("workflowweb@shinhint.gd.cn","Automatic(自动化)"); //附件 if (attech != "") { string[] attArray = attech.Split(','); foreach (string a in attArray) { string strFilePath = @a; Attachment attachment1 = new Attachment(strFilePath); attachment1.Name = System.IO.Path.GetFileName(strFilePath); //attachment1.NameEncoding = Encoding.UTF8; attachment1.TransferEncoding = System.Net.Mime.TransferEncoding.Base64; 内嵌式附件 //attachment1.ContentDisposition.Inline = true; //attachment1.ContentDisposition.DispositionType = // System.Net.Mime.DispositionTypeNames.Inline; //attachment1. mlMsg.Attachments.Add(attachment1); } } SmtpClient smtpClient = new SmtpClient("mailshinhint.shinhint"); smtpClient.Credentials = new NetworkCredential("workflowweb", "1234"); //smtpClient.Timeout = 1000; smtpClient.EnableSsl =false; smtpClient.Send(mlMsg); } // catch {} } } ////// 发送邮件方法 //////邮件地址///主题///内容///发送成功/// 创建日期:2008-7-20 /// 创建人:龚德辉 public static Boolean new_mail(string m_add, string m_sub, string m_body)//创建Mail,填入发送人,主题,內容 { try { MailMessage msz = new MailMessage();//建立邮件对象 msz.To = m_add; //string email是对方邮箱地址 //msz.From = "workflow@solartech.com.cn"; msz.From = "workflowweb@shinhint.gd.cn"; //可以是任意可用smtp地址 msz.Subject = m_sub; //邮件标题 msz.Body = m_body; msz.BodyFormat = MailFormat.Html; msz.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");//是否需要验证,一般是要的 msz.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "workflowweb");//自己邮箱的用户名 msz.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "1234");//自己邮箱的密码 SmtpMail.SmtpServer = "mailshinhint.shinhint";// 服务器地址 SmtpMail.Send(msz); //发送 return true; } catch { return false; } } #endregion
[C#]邮件发送
关注
打赏