Click here to Skip to main content
15,896,348 members
Articles / Desktop Programming / MFC
Article

Send ASP email with attachments

Rate me:
Please Sign up or sign in to vote.
2.11/5 (8 votes)
28 Apr 2002 134.4K   34   9
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.

VBScript
<%
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


Written By
Web Developer
Argentina Argentina
Lic. Fernando Finelli

Comments and Discussions

 
GeneralEnvio de adjuntos con cdonts Pin
la productora22-Jun-09 4:52
la productora22-Jun-09 4:52 
Questionhow to attach file from local system Pin
Y_Kaushik5-Aug-07 22:06
Y_Kaushik5-Aug-07 22:06 
QuestionWhere is the Attachment??? Pin
Small Rat18-Feb-05 9:49
Small Rat18-Feb-05 9:49 
AnswerRe: Where is the Attachment??? Pin
Nicebrilliant4-Jun-07 19:31
Nicebrilliant4-Jun-07 19:31 
AnswerRe: Where is the Attachment??? Pin
Nicebrilliant4-Jun-07 19:33
Nicebrilliant4-Jun-07 19:33 
GeneralCDONTS.DLL File Pin
Anonymous27-Mar-03 10:21
Anonymous27-Mar-03 10:21 
GeneralRe: CDONTS.DLL File Pin
Valer BOCAN28-Jul-03 23:15
Valer BOCAN28-Jul-03 23:15 
Generalfdgfdg Pin
Anonymous9-Sep-02 5:50
Anonymous9-Sep-02 5:50 
Generalsend email Pin
Shotgun11-Jul-02 11:14
Shotgun11-Jul-02 11:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.