본문 바로가기

프로그래밍

ASP - 메일보내기 샘플

출처 : http://devnote7.tistody.com  

<%

function GetMailForm(MailBody) '폼메일 contents
dim obj,FilePath,MailContent

' FileSystemObject 를 사용하여 해당파일의 내용을 text 형식으로 읽어온다.

Set obj = Server.CreateObject("Scripting.FileSystemObject")
FilePath = Server.MapPath(MailBody)

Set MailContent = obj.OpenTextFile(FilePath,1)
GetMailForm = MailContent.readall

MailContent.Close
Set MailContent = Nothing

Set obj = Nothing
end function

' 아래 -?????- 로 된부분 MAIL.html 파일에서 값들을 저장할 부분 .
' HBody에 폼을 받아 각각의 값들을 replace

HBody = GetMailForm("./Mail.html")
HBody = HBody
HBody = replace(HBody,"-nametxt-", sName &" 님께서 "& Left(Now(),10) &" 문의하신 내용입니다.")
HBody = replace(HBody,"-sEmailTitle-", sTitle)
HBody = replace(HBody,"-sEmailContent-", replace(sContents,chr(13)&chr(10),"<br>"))
HBody = replace(HBody,"-sTel-", sTel)
HBody = replace(HBody,"-sCateName-", sCateName)
HBody = replace(HBody,"-sEmail-", sEmail)
HBody = replace(HBody,"-sReRegDate-",Left(Now(),10))

' 메일 설정

Set Conf = CreateObject("CDO.Configuration")
With Conf.Fields
'로컬호스트를 이용할 경우
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\Inetpub\mailroot\Pickup"
.Update
End With

Set srMail = Server.CreateObject("CDO.Message")
with srMail
.Configuration = Conf
.From = sName & "<" & sEmail & ">"
.To = mailToTxt
.Subject = sName & " 님께서 "& Left(Now(),10) &" 문의하신 내용입니다."
.HtmlBody = HBody
.Send
end with
Set Conf = Nothing
Set srMail = nothing

%>