Function SendMail 외부 서버를 이용한 메일 발송 방법

Public Function SendMail(strSenderName, strSenderAdd, strReceiverName, strReceiverAdd, strSubject, strMailBody, sFileName)

SendMail = False ‘메일에러체크

sFrom = “”&strSenderName&”” & “<“& strSenderAdd &”>”       ‘송신자설정
sTo  = “”&strReceiverName&”” & “<“& strReceiverAdd &”>”     ‘수신자설정

Set objMail = Server.CreateObject(“CDO.Message”)

Set mailConfig = objMail.Configuration

With mailConfig.Fields
   .Item(“http://schemas.microsoft.com/cdo/configuration/sendusing“) = 1 ‘1 : 로컬 SMTP / 2 : 외부 SMTP
‘.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory“) = “c:\inetpub\mailroot\pickup”
.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver“) = “localhost” ‘외부 서버 IP 또는 도메인
.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport“) = 25
.Item(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout“) = 30
.Update
End With

Set mailConfig = Nothing

objMail.From  = sFrom
objMail.To   = sTo
‘ objMail.cc = “mandar.date@gmail.com”  ‘참조
‘ objMail.bcc = “datemandar@yahoo.com;mandar.date@india.com”  ‘숨은참조
objMail.Subject  = strSubject
objMail.HTMLBody = strMailBody
objMail.BodyPart.Charset = “UTF-8”
objMail.HTMLBodyPart.Charset = “UTF-8”

If Len(sFileName) > 3 Then
objMail.AddAttachment sFileName
End If

objMail.Send

Set objMail = Nothing

If Not Err Then
SendMail = True
End If

Response.Write “메일 발송 완료”

End Function

FromName = “TEST”
FromEmail = “메일@한국.com”
Toname = “고객님”
ToEmail = “고객@한국.com”
Subject = “한국에서 메일보내기”
Message = “한국 입니다..”
rFilePath = “”

bMsg = SendMail(FromName , FromEmail , ToName , ToEmail , Subject , Message, rFilePath)