Tuesday, May 27, 2008

Send Mail

Send mail using Persits component
//Declare mail object
Set objPersits = Server.CreateObject("Persits.MailSender")

With objPersits
.From = "sree@yahoo.com" //From Email Id
.FromName = "Sree" //Name of the Sender
.Host = "mail.domain.com" //Mail Host
.Subject = "Invitation"
.AddAddress mailTo,mailName
.Body = mailbody
.isHTML = True //If html content exists in the mail body
on error resume next
.Send //To send mail finally
if err.number <> 0 then
response.write "Error " & err.number & " sending to " & mailTo & " (" & mailName & ")"
//To know the description of the error, we give
response.write err.description
err.clear
else
//Mail has been sent
end if
.RemoveAddress mailTo, mailName
End With

set objPersits = nothing


How to send an external html file through mail?
//Declare file system object to read from the file
set fso = Server.CreateObject("Scripting.FileSystemObject")

//Specify File location
fname = "/AffiliateEmails/affmail.htm"

//Open a file using above object and set it to a new object
set fObj = fso.openTextFile(server.mappath(fname))

//Read from the file and assign to a variable which is further assigned to the .Body of the mail
mailBody = fObj.readAll

//Close the connection to the file
fObj.close

set fso = nothing

No comments: