Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Send ASP email with attachments

0.00/5 (No votes)
28 Apr 2002 1  
Send ASP email with attachments

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")

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here