C#
SMTP로 메일 보내기
캡틴노랑이
2018. 11. 8. 16:09
반응형
DevExpress의 Report의 PDF 문서를 MemoryStream으로 받은 다음에 C#의 SMTP를 이용하여 메일로 전송.
//using System.Net; //using System.Net.Mail; using (MemoryStream stream = new MemoryStream()) { report.ExportToPdf(stream); byte[] bytes = stream.ToArray(); try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("mail.test.co.kr"); string msg = GetMailTempleate(); msg = msg.Replace("[MailTitle]", "발주서 자리"); msg = msg.Replace("[name]", ds.Tables[0].Rows[0]["USRNM"].ToString()); //msg = msg.Replace("[Position]", ds.Tables[0].Rows[0][""].ToString()); //msg = msg.Replace("[part]", ""); msg = msg.Replace("[address]", ds.Tables[0].Rows[0]["ADDR"].ToString()); msg = msg.Replace("[phone]", ds.Tables[0].Rows[0]["OFFICE_TEL"].ToString()); msg = msg.Replace("[fax]", ds.Tables[0].Rows[0]["FAX_NUM"].ToString()); mail.From = new MailAddress("finalwarrior@naver.com"); mail.To.Add(new MailAddress("finalwarrior@naver.com")); mail.Subject = "발주서 명칭???"; mail.Body = msg; mail.Attachments.Add(new Attachment(new MemoryStream(bytes), "test.pdf" ));//, "application/pdf" mail.IsBodyHtml = true; SmtpServer.Port = 5878; SmtpServer.Credentials = new System.Net.NetworkCredential("test@test.co.kr", "*******"); SmtpServer.EnableSsl = true; //SmtpServer.Timeout = 5; SmtpServer.Send(mail); MessageBox.Show("mail Send"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
반응형