Relay All ASP Email to outside SMTP?

Posted on 2006-04-12
Last Modified: 2010-08-05
When I send email through an ASP page through my local "intranet" it sends through the normal IIS Default SMTP server.  Is there a way to make an external SMTP server the default.  In other words I want all email through ASP to be sent through  Is this possible?
Question by:gillweb
    LVL 1

    Accepted Solution

    What email component are you using?  Most of them allow you to specify what mail server to send through.  If you're using CDO, you can use this code:

    Const cdoSendUsingMethod        = _
    Const cdoSendUsingPort          = 2
    Const cdoSMTPServer             = _
    Const cdoSMTPServerPort         = _
    Const cdoSMTPConnectionTimeout  = _
    Const cdoSMTPAuthenticate       = _
    Const cdoBasic                  = 1
    Const cdoSendUserName           = _
    Const cdoSendPassword           = _

    Dim objConfig  ' As CDO.Configuration
    Dim objMessage ' As CDO.Message
    Dim Fields     ' As ADODB.Fields

    ' Get a handle on the config object and it's fields
    Set objConfig = Server.CreateObject("CDO.Configuration")
    Set Fields = objConfig.Fields

    ' Set config fields we care about
    With Fields
          .Item(cdoSendUsingMethod)       = cdoSendUsingPort
          .Item(cdoSMTPServer)            = "smtp_server_name"
          .Item(cdoSMTPServerPort)        = 25
          .Item(cdoSMTPConnectionTimeout) = 10
          .Item(cdoSMTPAuthenticate)      = cdoBasic
          .Item(cdoSendUserName)          = "username"
          .Item(cdoSendPassword)          = "password"

    End With

    Set objMessage = Server.CreateObject("CDO.Message")

    Set objMessage.Configuration = objConfig

    With objMessage
          .To       = "Display Name <email_address>"
          .From     = "Display Name <email_address>"
          .Subject  = "SMTP Relay Test"
          .TextBody = "SMTP Relay Test Sent @ " & Now()
    End With

    Set Fields = Nothing
    Set objMessage = Nothing
    Set objConfig = Nothing

    Alternatively, you could configure your local SMTP server as a smarthost to another mail server.
    LVL 18

    Expert Comment

    by:Sam Panwar

    This is possible through the ASP for it you can use the CDOSYS code CDOSYS support Window 2003 and forwindow 2000 server  CDONTS
    /Use the following code in your asp page

    Use following code for CDOSYS Email componets.
    Set cdoConfig = Server.CreateObject("CDO.Configuration")
    cdoConfig.Fields.Item(sch & "sendusing") = 2
    cdoConfig.Fields.Item(sch & "smtpserver") = ""
    Set cdoMessage = Server.CreateObject("CDO.Message")
    Set cdoMessage.Configuration = cdoConfig
    cdoMessage.From =
    cdoMessage.To = "" = ""
    cdoMessage.Subject = "enquiry form CDOSYS componets"
    cdoMessage.HTMLBody = "your text"
    Set cdoMessage = Nothing
    Set cdoConfig = Nothing
    response.redirect= ""

    For CDONTS:
    01. <%
    02. Dim objCDOMail
    03. Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
    04. objCDOMail.From = ""
    05. objCDOMail.To = ""
    06. objCDOMail.Cc = ""
    07. objCDOMail.Bcc = ""
    08. objCDOMail.Subject = "Subject"
    09. objCDOMail.BodyFormat = 0
    10. objCDOMail.MailFormat = 0
    11. objCDOMail.Body = "MailBody"
    12. objCDOMail.Importance = 1
    13. objCDOMail.Send
    14. Set objCDOMail = Nothing
    15. %>
    Explanation According to Line
    01. Open ASP tag
    02. Declare a variable named objCDOMail
    03. Create instance of Mailer control
    04. Set Mailer control properties and collection items
    05. Set Mailer control properties and collection items
    06. Set Mailer control properties and collection items
    07. Set Mailer control properties and collection items
    08. Set Mailer control properties and collection items
    09. Set Mailer control properties and collection items
    10. Set Mailer control properties and collection items
    11. Set Mailer control properties and collection items
    12. Set Mailer control properties and collection items
    13. Send Mail
    14. Release resources
    15. Close ASP tag

    IF you get error then may be your server have not installed CDOSYS check and then try
    LVL 10

    Expert Comment

    there is an option of smart host in IIS SMTP server. there i think you can give your ISP`s SMTP server

    Author Comment

    This SmartHost seems like the way to go since apparently the CDOSYS option isn't on my machine?  Can some one explain how I tell IIS to send mail through an ISP SMTP?

    Author Comment

    gexen....i think your solution for CDO is working.  Is there a way to make this a FUNCTION to be able to import it into different pages easily?

    Author Comment

    I keep getting IIS shutting down giving me an error stating this:

    zAppName : inetinfo.exe     szAppVer : 5.1.2600.2180    
    szModName : ntfsdrv.dll     szModVer : 6.0.2600.1     offset : 000032e3

    Any ideas?
    LVL 18

    Expert Comment

    by:Sam Panwar

    for your information cdosys is already installed on the window server 2003 if you have installed the .

    This ntfs file error this may due to the permission of the IIS file in th ntfs
    you have any changes in the IIS recently or permission

    check the permission and event viewer for more erro discription
    LVL 18

    Expert Comment

    by:Sam Panwar
    Also check the metabase setting of IIS

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    powershell for updating 301 redirects IIS 2 29
    Leverage browser caching 2 41
    Kerberos / NTLM 3 44
    How to run mscorfcfg.msc 7 32
    First of all, clustering IIS is something you should rarely consider doing. In almost all cases, Microsoft Network Load Balancing (NLB) ( is a much better solution when you need to p…
    What is an ISAPI filter?   •      It's an assembly (.dll file) that can add or change the way IIS works.   •      They can be enabled globally for your web server or on a site-by-site basis.   When the IIS server receives a request, enabling the ISAPI fi…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now