Sending E-Mails with ASP Pages

Discussion in 'ASP' started by pradeep, May 1, 2005.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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:
    <%
    	Option Explicit
    
    	Dim objCDOMail
    	Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
    %>
    The methods and property's of this object are very obvious.

    Code:
    <%
    	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:
    <%
    	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.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Nice and simple way to send an email.
     
  3. Bhavin

    Bhavin New Member

    Joined:
    Oct 13, 2005
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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.
     
  5. hasmukh

    hasmukh New Member

    Joined:
    Jul 31, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Good Info Thanks


    :) HASMUKH :)
     
  6. himali

    himali New Member

    Joined:
    Sep 21, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  7. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice