IT/C#
[C#] SMTP 465 PORT 메일 보내기
시린스
2022. 8. 19. 18:11
반응형
매번 SMTP를 25번 , 587번으로만 보내다가 465 Port는 보내지지 않았었는데
해당 아래 소스로 465번 포트도 보내지는 것을 확인했다.
아래 소스로 이메일 전송 로직을 만들었다.
[HttpPost]
public void SendEmail_PORT465(HttpFileCollectionBase files, string strPath, string strSubject, string strBody)
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.Subject = strSubject;
msg.Body = strBody;
msg.BodyFormat = System.Web.Mail.MailFormat.Html;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.From = "From";
msg.To = "To";
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "Host");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//User name
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "smtp ID");
//Password
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "smtp PW");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
System.Web.Mail.SmtpMail.SmtpServer = "smtp Host";
System.Web.Mail.SmtpMail.Send(msg);
}