Introduction
This article shows how to send an email with attachments using the CDONTS component.
Many ASP programmers want to know how to do this and with the arrival of IIS4 and the SMTP service of Option Pack 4 it is now fairly easy. There is a component that is made available after the server installation of SMTP service. It is called CDONTS and it makes sending email rather easy. Setting up the SMTP service properly is up to you. It is fairly self explanatory and I have never had any problems installing it. Any quality ISP's who offer ASP hosting should already have this set up on their servers.
<%
Sub send_email(strEmail_from, strEmail_to, strEmail_subject, _
strEmail_body, strEmail_attach)
Dim Newmail
Set newmail = server.CreateObject ("cdonts.newmail")
newmail.bodyformat = 0
newmail.mailformat = 0
newmail.from = strEmail_from
newmail.to = strEmail_to
newmail.subject = strEmail_subject
If strEmail_attach <> "" then
newmail.AttachFile(strEmail_attach)
End If
newmail.body = strEmail_body
newmail.send
Set newmail = Nothing
End Sub
%>
Call Example:
Call send_email("Email_from", "Email_to", "Email_subject", _
"Email_body", "c:\file.doc")