Is it possible to configure MSAccess 2010 to send emails with Outlook 365?
If so, how?
Original VBA code to send email using Outlook 2010:
Private Sub Send_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim strTemp As String
Dim lngCount As Long
Dim varProxies As Variant
Dim ctlSource As Control
Dim ctlDest As Control
Dim intCurrentRow As Integer
Set ctlSource = Forms![send mail]!recipients
On Error GoTo ErrorMsgs
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message. Substitute
' your names here.
Set ctlSource = Forms![send mail]!recipients
For intCurrentRow = 0 To ctlSource.ListCount - 1
Set objOutlookRecip = .recipients.Add(ctlSource.Column(0, intCurrentRow))
objOutlookRecip.Type = olTo
Next intCurrentRow
' Add the CC recipient(s) to the message.
'Set objOutlookRecip = .recipients.Add("HughP@aberdeencity.gov.uk")
'objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message.
'.Sender.Address = Forms![send mail]!Sender
.Subject = Forms![send mail]!Subject
.Body = Forms![send mail]!Message
.Importance = olImportanceNormal 'High Normal or Low importance
' Add attachments to the message.
If Not IsNull(Forms![send mail]!attach1) Then
.Attachments.Add (Forms![send mail]!attach1)
End If
If Not IsNull(Forms![send mail]!attach2) Then
.Attachments.Add (Forms![send mail]!attach2)
End If
If Not IsNull(Forms![send mail]!attach3) Then
.Attachments.Add (Forms![send mail]!attach3)
End If
If Not IsNull(Forms![send mail]!attach4) Then
.Attachments.Add (Forms![send mail]!attach4)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .recipients
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
If Forms![reqf]![chkemailitrf] = True Then
Forms!reqf![AgSent] = Now
ElseIf Forms![reqf]![chkemailjcf] = True Then
Forms!reqf![ClSent] = Now
End If
DoCmd.Close acForm, "[send mail]", acSaveNo
ErrorMsgs:
If Err.Number = "287" Then
MsgBox "You clicked No to the Outlook security warning. " & _
"Rerun the procedure and click Yes to access e-mail" & _
"addresses to send your message. For more information, " & _
"see the document at http://www.microsoft.com/office" & _
"/previous/outlook/downloads/security.asp. "
End If
Me.Sender.SetFocus
DoCmd.Close
Exit Sub
End Sub
Steve