.Net/SQL - Best way to send email through exchange server - SQL (not outlook) - anyone done this?

Posted on 2009-12-17
Last Modified: 2012-06-27
Hello all,

I have an application that I am going to need to send email from.  I have used in the past outlook with CDONTS etc. however it is very messy and usually you have to deal with the security warning issues and use outlook redepemtion etc. to send the emails.  I think it is a very messy and performance beast.   Has anyone sent email through .Net through exchange or a web service for exchange etc?  The client has exchange for their mail server and of course outlook clients connecting to the users mailboxes.

I am trying to find the best solution and also any insight on what things I need to find out like what exchange version, what I will need to setup on the server running the app that is going to send out emails etc.  I am going to have SQL Server also where then email addresses exist.  I want it to be as seamless as possible and not hold up the app. The app is going to loop and send out multiple emails on an hourly basis.

Thanks all
Question by:sbornstein2
    LVL 7

    Expert Comment

    How about this piece of VBS code?


    Sub DropEmail(MsgFrom, MsgTo, MsgSubject, MsgBody)
    'on error resume next
    Dim iConf
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields
    Flds("")  = 2
    Flds("") = "someexchangeserver.yourdomain.local"
    Flds("")   = 25
    Flds("") = cdoAnonymous ' 0
    WScript.Echo "Attempting to send email using smtp server: " & someexchangeserver.yourdomain.local
    Dim iMsg
    set iMsg = CreateObject("CDO.Message")
    With iMsg
      Set .Configuration = iConf
        .To          = MsgTo
        .From        = MsgFrom
        .Sender      = MsgFrom
        .Subject     = MsgSubject
        .TextBody    = MsgBody
    '    .HTMLBody    = MsgBody
    End With
    'on error goto 0    
    End Sub

    Open in new window

    LVL 7

    Accepted Solution

    Or this (using the "pickup" folder share on the server):

    Sub DropEmail(MsgFrom, MsgTo, MsgSubject, MsgBody)
    'on error resume next
    Dim strDropBox, intRandom
        strDropBox = "\\yourexchangeserver.yourdomain.local\Pickup\"
        WScript.Echo "Sending email to " & MsgTo & " using " & strDropBox
        upperbound = 999
        lowerbound = 1
        intRandom = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
        Set EmailFile=fs.OpenTextFile(strDropBox & "email." & intRandom,8,TRUE)
        EmailFile.Writeline "x-sender: " & MsgFrom
        EmailFile.WriteLine "x-Receiver: " & MsgTo
        'EmailFile.WriteLine "From: " & MsgFrom
        EmailFile.WriteLine "From: " & UsersName & "@" & ComputersName & "." & UsersDomain & ".COM"
        EmailFile.WriteLine "To: " & MsgTo
        EmailFile.Writeline "Subject: " & MsgSubject
        EmailFile.WriteLine MsgBody
    'on error goto 0    
    End Sub

    Open in new window


    Author Comment

    It is going to be emailed attachmented excel files to the email.  I need to attach a created excel ti the email and then send.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Email statistics and Mailbox database quotas You might have an interest in attaining information such as mailbox details, mailbox statistics and mailbox database details from Exchange server. At that point, knowing how to retrieve this information …
    Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
    In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    734 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

    18 Experts available now in Live!

    Get 1:1 Help Now