Sending E-Mails with ASP Pages

pradeep's Avatar author of Sending E-Mails with ASP Pages
This is an article on Sending E-Mails with ASP Pages in ASP.
Sending an email with asp is fairly easy, all you need is CDONTS (Collaboration Data Objects for NT Server, installed with IIS), or a special component like SMTPmail by SoftArtisans, or AspEmail ( free ) by Persits Software Inc (there are more available).

In this article I'll show how to send emails with CDO, because it's available to everyone and
components work in a very similar way. First we have to create instance of the NewMail object.

Code: ASP
<%
    Option Explicit

    Dim objCDOMail
    Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
%>
The methods and property's of this object are very obvious.

Code: ASP
<%
    objCDOMail.To = "somebody@somewhere.com"   'the destination
    objCDOMail.From = "me@mydomain.com"   '
the sender
    objCDOMail.cc = "info@mydomain.com"   'carbon copy

    Dim txtBody
    txtBody = "This email has been sent by an asp script"
    objCDOMail.Subject = "CDONTS"   '
the subject
    objCDOMail.Body = txtBody   'the body
    objCDOMail.Send   '
fire off the email
%>
So far it has been pretty easy, hasn't it? There's more.

Code: ASP
<%
    objCDOMail.AttachFile("c:\wwwroot\mysite\" & _
        "
MyAttachement.doc", "pricelist.doc")
    objCDOMail.Bcc("
blind@mysite.com")
    objCDOMail.Importance = 1
%>
The first rule defines an attachment ("PATH\TO\FILE", filename_that_appears)
The second rule sends a blind carbon copy The third rule specifies the message's importance

Importance:
0 -> low
1 -> default
2 -> high

Thats it, I hope this article has been useful and i hope that now you will feel confident sending automated newsletters, confirmation emails and so on.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Nice and simple way to send an email.
Bhavin's Avatar, Join Date: Oct 2005
Newbie Member
hi,
i had used the code to send mail but the mail are goes to the bulk folder of the user.
Please tell me what will i do so the mail is goes to the inbox not to the bulk folder.
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Hi,
The mail goes to the Bulk Folder because the your mail provider detected it as spam. If the mail does not come from a listed Mail Server, it is usually considered as spam.
http://dsbl.org/main
http://www.spamhaus.org/xbl/
check these links, if your IP is present in their database, some servers might not even accept the mail.
So, one thing you can do is get your SMTP server registered there.
hasmukh's Avatar, Join Date: Jul 2006
Light Poster
Good Info Thanks


HASMUKH
himali's Avatar, Join Date: Sep 2008
Newbie Member
is there any way i can add headers in email?

im using cdo object but i can't find a clue about how to add header

for example:

Microsoft Mail Internet Headers Version 2.0

Received: from (IP) ([IP]) by SERVERNAME ([IP]) with Microsoft Exchange Server HTTP-DAV ;

Wed, 10 Sep 2008 16:02:39 +0000

User-Agent: Microsoft-Entourage/11.4.0.080122

Date: Wed, 10 Sep 2008 17:00:29 +0100

Subject: Test for agent

From: SENDER <SENDER@SOMEONE.co.uk>

To: <RECEIVER@SOMEOTHER.com>

Message-ID: <C4EDADAD.53FB%SENDER@SOMEONE.co.uk>

Thread-Topic: Test for agent

Thread-Index: AckTXliJls/D+H9REd2DXwAX8sdIJQ==

X-Priority: 1

Mime-version: 1.0

Content-type: text/plain;

charset="US-ASCII"

Content-transfer-encoding: 7bit