Discussion Locked

Sending e-mail from Access

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Would like to know how to send e-mails directly from access using the e-mail address we maintain in access.

10 replies

by dklippert

SendObject is the action. You can contstruct a macro to do this.
For instructions, type e-mail in the keyword box on the index tab of the Help file.
Here's an article. (Faxing and sending e-mail are the same)

TYpe the Q number in the search boxat support.microsoft.com

How to Fax from Microsoft Access Using SendObject Command

Q145787

by chrissaw

Hi mrs MRS,

Here the procedure I use to do what you want to do. Just call the Proc by Call SendEmail.
You have to use your table name instead of mine ie, "tblConstantesOutlook" and the field name GLO_EMAIL_TO by your field name containing email address.
I took off all error handling and comments to fit in this textbox.

Hope it will help.
Christian

Public Sub SendEmail()
Dim dbOutlook As DAO.Database
Dim recOutlook As DAO.Recordset
Dim oOutlookApp As Outlook.Application
Dim oMailItem As Outlook.MailItem
Dim oNameSpace As Outlook.NameSpace
Dim pAttachment As Outlook.Attachments
Dim strNewFName As String
Dim strFName As String

On Error Resume Next
Set oOutlookApp= GetObject(Class:="Outlook.Application")
If oOutlookApp Is Nothing Then
Set oOutlookApp = New Outlook.Application
End If
If oOutlookApp Is Nothing Then
MsgBox "Did not get Outlook instance" & vbCrLf _
& Err.Number & " " & Err.Description, vbInformation
Exit Sub
End If
Set dbOutlook = CurrentDb
Set recOutlook = dbOutlook.OpenRecordset("yourTableName", dbOpenDynaset)
Set oMailItem = oOutlookApp.CreateItem(olMailItem)
SetoNameSpace = oOutlookApp.GetNamespace("MAPI")
Set pAttachment = oMailItem.Attachments
Call oMailItem.Recipients.Add(Trim(recOutlook![GLO_EMAIL_TO]))
oMailItem.Subject = Trim(recOutlook![GLO_EMAIL_SUBJECT])
If IsNoData(glbEmailBodyComments) Then
oMailItem.Body = Trim(recOutlook![GLO_EMAIL_BODY])
Else
oMailItem.Body = glbEmailBodyComments
End If
pAttachment.Add Trim(recOutlook![GLO_EMAIL_PATH]) & Trim(recOutlook![GLO_EMAIL_ATTACHMENT]), olByValue
oMailItem.Save
oMailItem.Send
Set oMailItem = Nothing
Set oNameSpace = Nothing
Set pAttachment = Nothing
oOutlookApp = Nothing
End Sub

by chrissaw

Hi again,
I forgot to tell you that you must add a reference to your Access database for Microsoft Outlook 8.0 or 9.0 or 10.0 Library depending of your release of Office.

Christian

by mrs mrs

Am doing this instead of using distribution lists in outlook. Where would I loop through the contacts, when there are more than one?

by timfox

Check out this web site (it was referred to me by another TechRepublic user ages ago.

http://www.granite.ab.ca/access/email.htm

I used the references there to send mail with a Lotue Notes client - which worked great, but I haven't had to use the Outlook MAPI method.
Hope it helps.

This discussion is closed to new replies.