It used to be you could send out emails through outlook from Access, but
now Outlook has all these security prompts each time you interface with
Outlook - which makes it pretty much unsuable from/through automation.
The easiest solution I came up with was to write my own Emailer program
in VB.Net which contains all the classes required for emailing using
whatever mail server Outlook would use. I can read the email addresses
from an Access mdb and then send them out through my emailer program --
adding a generic subject line/body.
I realize this is not a .Net forum, but incase anyone cares, here is the
part of the .Net code which would send out the emails:
-------------------------------------------
Imports System
Imports System.Data
Imports System.Net.Mail
Imports System.IO
Private Sub SendTheEmail()
Try
Dim Client As SmtpClient
Dim Message As MailMessage
Dim strRegex As String
strRegex =
"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-
Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
Dim Expression As New System.Text.RegularExpressions.Regex(strRegex)
Message = New MailMessage
Message.From = New MailAddress(txtFrom.Text)
For Each dr As DataRow In tblEmail.Rows
'--validate email before adding to Send Email list
If Not Expression.IsMatch(dr("Email").ToString) Then
Throw New System.Exception("Invalid Email Address Exception has
occured for " & dr("ID_Main").ToString & " " & dr("Email").ToString)
Else
Message.To.Add(New MailAddress(dr("Email").ToString))
End If
Next
Message.Subject = txtSubject.Text
Message.Body = rtbBody.Text
Message.IsBodyHtml = True '-- use this if formatting with
'--html tags else exclude this line
'--my Outlook was using the comcast email server
Client = New SmtpClient("mail.comcast.com")
Client.Send(Message)
MessageBox.Show("done sending mail!")
Catch ex As Exception
MessageBox.Show(ex.ToString, "Problem with Email",
MessageBoxButtons.OK)
End Try
End Sub
----------------------------------------------
tblEmail is a .Net dataTable contained in the Emailer program which
contains the email addresses to mail to imported from an Access mdb.
This .Net program could also be created as a DLL which could be
referenced from an Access mdb, and actually, I could have eliminated the
.Net loop and just looped in Access -- calling the .Net dll for each
iteration of the loop. But instead I just read the whole table into the
.Net program and just emailed everything in one shot. The .Net program
also performs email validation using a Regular Expression - which this
could also be done directly in Access by Referencing RegEx in
Tools/References.
Rich
*** Sent via Developersdex
http://www.developersdex.com ***