[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

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

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
0
sbornstein2
Asked:
sbornstein2
  • 2
1 Solution
 
CompanionCubeCommented:
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("http://schemas.microsoft.com/cdo/configuration/sendusing")  = 2
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "someexchangeserver.yourdomain.local"
Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverport")   = 25
Flds("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous ' 0
Flds.Update

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
    .Send
End With

'on error goto 0    
End Sub

Open in new window

0
 
CompanionCubeCommented:
Or this (using the "pickup" folder share on the server):
http://support.microsoft.com/kb/306043

~~~
Sub DropEmail(MsgFrom, MsgTo, MsgSubject, MsgBody)
'on error resume next
Dim strDropBox, intRandom
    Randomize
    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 
    EmailFile.WriteLine MsgBody
    EmailFile.Close
'on error goto 0    
End Sub

Open in new window

0
 
sbornstein2Author Commented:
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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now