vbscript to send email to exchange server 2007?
I have an access database (vb) that I need to add vbscript into to be able to create and send email thru an exchange server 2007. Previous code used CDO which is no longer part of the install of Ex 2007, and most are reluctant to install. So I need to find a different protocol to use...I do have Outlook 2007 setup and successfully sending e-mails to the ex 2007. I thought Outlook 2007 used MAPI, but I tried vbscript using MAPI code and that only lead to the error message of "ActiveX component missing. Can't create object". The intent is to include code where a client email app is not required. Also, most also do not want to turn on SMTP relaying, so that is also not an option.Can someone share vbscript code that can be used with VB 6.5 and exchange server 200 to send simple e-mails with multiple attachments capability?I looked at the msdn http://msdn.microsoft.com/en-us/library/aa494235(EXCHG.80).aspx but could not figure out how to find out what the conn.provider should be with my installation, and not sure if the sMailBoxURL is required, and if so what mine would be....and also it suggests using CDO to create the object. Since CDO in not part of the normal install, most are reluctant to add after-the-fact...I would like to be able to look at my Outlook 2007 setting and fill-in-the blank vbscript...perhaps wishful thinking..Thanks!
February 2nd, 2010 10:11pm
Why not use PowerShell which is native to Exchange and embed your VBScript?
How To Re-Use VBScript In PowerShell?
http://www.out-web.net/?p=130
This code snippet is adapted from Tony Redmond’s Exchange 2007 book. It assumes that the Exchange Hub Transport server allows to relay messages.
It picks up uploaded PDF files …
# Create new object of type .NET
$smtpClient = New-Object System.Net.Mail.SmtpClient
# Your Exchange Server (Hub Transport)
$smtpClient.host = 'remote.snøås.net'
# The Message
$from = 'ftp@snøås.net'
$to = 'jas@snøås.net'
$msgTitle = 'Another .PDF Attachment'
$msgBody = 'This attachment has been uploaded to our server'
# Add an attachment
$pdfFile = 'C:\temp\targetAddress.pdf'
$msgAttachment = New-Object System.Net.Mail.Attachment ($pdfFile)
# Send the message
$smtpClient.Send($from, $to, $msgTitle, $msgBody)
You can easily change this and pass crendentials$SmtpClient.UseDefaultCredentials = $True
Or
$Credentials = New-ObjectSystem.Net.NetworkCredential(‘Redmond@xyz.com’, ‘Password’)SmtpClient.Credentials = $Credentials
Including credentials in plain text in a script isn’t very secure. You can doa much better job by prompting the user for credentials to use:
$Credentials = Get-Credential
This command puts up a standard Windows login dialog for the user toinput their username and password. We can then fetch the data and store itas follows:
$Username = $Credentials.Username$Password =$Credentials.GetNetworkCredential().Password$Credentials2 = New-ObjectSystem.Net.NetworkCredential($UserName,$Password)SmtpClient.Credentials = $Credentials2
Adpated from Microsoft® Exchange Server 2007 with SP1:Tony Redmond’s Guide to Successful Implementationhttp://www.amazon.com/Microsoft-Exchange-Server-2007-Implementation/dp/1555583474
MCTS: Messaging | MCSE: S+M | Small Business Specialist
Free Windows Admin Tool Kit Click here and download it now
February 3rd, 2010 2:53am