public static void FileMailSend(string filePath, string msg)
{
MailMessage mail = new MailMessage();
//보내는 사람 이메일
mail.From = new MailAddress("impelhaihm@gmail.com");
//반는사람 이메일
mail.To.Add("ToMailAdress");
//메일제목
mail.Subject = "SpcAutoDrafts Error";
//메일내용
mail.Body = msg;
//첨부파일
System.Net.Mail.Attachment attachment;
//첨부파일 붙이기
attachment = new System.Net.Mail.Attachment(filePath);
mail.Attachments.Add(attachment);
//gmail 포트 설정
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
//SSL 설정 (gmail 은 ture로 설정, 메일 서버 세팅에 따라 다름)
smtp.EnableSsl = true;
//gamil 인증을 위한 id/pw (보내는사람 정보 넣기)
smtp.Credentials = new NetworkCredential(" Email Adress ", " passworld ");
try
{
smtp.Send(mail);
}catch
{
MessageBox.Show("메일발송실패");
}
}
'언어 > C#' 카테고리의 다른 글
[숙제] 2021.09.29 (0) | 2021.09.29 |
---|---|
C# Build Error (0) | 2020.09.07 |
C# ] Dll 참조 (0) | 2019.10.02 |
Show / ShowDialog (0) | 2019.10.01 |
연산자 (0) | 2019.10.01 |