Tuesday, March 17, 2009

Source Code for sending email with file attachment in Classic ASP

dim tend
tend="body text will be here"
Set objMail = Server.CreateObject("CDO.Message")
objMail.From = "abc@xyz.in"
objMail.To = "abc@xyz.in"
objMail.CC = "info@xyz.in"
objMail.BCC = "abc@xyz.in,mn0@xyz.in,dfg@xyz.in"
objMail.Subject = "subject will be here"
'objMail.BodyFormat = 0
'objMail.MailFormat = 0
objMail.HTMLBody = tend

' For attachement file
Dim strServerURL
'Server Name including http:// protocol
strServerURL = "http://" + Request.ServerVariables("SERVER_NAME")
Dim strServerURLFull
'Path to subweb directory
strServerURLFull = strServerURL & "/2008"
Dim strTargetURL
'Directory where file is located
strTargetURL = strServerURLFull & "/xyz"

dim strpath
strpath = strTargetURL & "/" & locatedfilename
objMail.AddAttachment(strpath)

if locatedfilename2 <> "" then
dim strpath2
strpath2 = strTargetURL & "/" & locatedfilename2
objMail.AddAttachment(strpath2)
end if

objMail.Send

No comments: