Click here to Skip to main content
Email Password   helpLost your password?

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")
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralEnvio de adjuntos con cdonts
la productora
5:52 22 Jun '09  
Hola, soy nuevo en ASP, estoy tratando de enviar adjuntos desde el email, necesitaria algún codigo que pueda adaptar a mi página. desde ya muchas gracias.
Pablo.
Generalhow to attach file from local system
Y_Kaushik
23:06 5 Aug '07  

Hello All's
I am New in asp ...
I am writing an script for sending email with attachment in asp
when i upload this file it show page can not be displayed
my code is below can any one told me where i am wrong

resum=Request.Form("fille1")


Dim myMail
Set myMail = CreateObject("CDONTS.NewMail")
myMail.From = "resume@test.com"
myMail.To = "yogendra.kaushik@gmail.com"
myMail.Subject = "Resume submission from website."
'myMail.AddAttachment Server.MapPath("resum")
myMail.AttachFile("resum")
myMail.BodyFormat = 0
myMail.MailFormat = 0
myMail.Body = fulldisplay
myMail.Send
Set myMail = Nothing
response.Redirect("msg.asp")

Please help me if any body can.........


Regard's
Kaushik

GeneralWhere is the Attachment???
alanshen209
10:49 18 Feb '05  
Hi,

I have a question about how to send an email with attachment, here is it:
We can just give a string of the filePath+FileName to AttachFile method, and then send it, My question is where is the file located? is it on the server of on the client side.

The client side I mentioned aboved means, I create an ASP page where the user can choose the files he/she wants it appears on the EMail. This way the file is on the client side(internet user's pc). Can we just use the file path or we have to upload the file to the server first and then use the server's file to attach it to the email?

Thanks a lot!!

Alan



Alan Shen

MCAD for .NET Version
^~^~^~^~^~^~^~^~^~^~^
Great idea is the beginging of success!
GeneralRe: Where is the Attachment???
Nicebrilliant
20:31 4 Jun '07  
If you are hosting your application on the server, then you need to save first on the server and then provide location of the file located on server.

E.g : when you attach file from your local system the path would be like this.

"c:\bob.jpg"

when you are attaching this file from server

Server.MapPath(" directory location ")

Hope will be the answer

BOB PK

Bob
Nature's Lover.

GeneralRe: Where is the Attachment???
Nicebrilliant
20:33 4 Jun '07  
If you are hosting your application on the server, then you need to save first on the server and then provide location of the file located on server.

E.g : when you attach file from your local system the path would be like this.

"c:\bob.jpg"

but while going to attach file,

Path would be like this Server.MapPath(" directory location ")

Hope will be the answer

BOB PK

Bob
Nature's Lover.

GeneralCDONTS.DLL File
Anonymous
11:21 27 Mar '03  
Where do i get the CDONTS.DLL File from as i cannot send emails from my asp page.
GeneralRe: CDONTS.DLL File
Valer BOCAN
0:15 29 Jul '03  
Host your ASP page on a server OS, such as Windows 2000 Server or Windows .NET Server. These come preconfigured with the CDONTS object.
Other than that, install Microsoft Outlook (from the Office package) on any workstation and that will install the much needed CDONTS Big Grin

Delta Forth .NET (www.dataman.ro) World's first Forth compiler for the .NET platform
Generalfdgfdg
Anonymous
6:50 9 Sep '02  
gdffdg
Generalsend email
shotgun
12:14 11 Jul '02  
Would you know how to "Authenticate" to your isp whaen sending email. In Outlook i must have it set to "Authenticate" when i send email, or i get an error. All the scripts i have found to send email never mention "Authenticate" and all error, any helps appreciated.

shotgun


Last Updated 29 Apr 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010