This is what I used
Code:
With objOutlookMsg
.Subject = .Subject & " - " & intTransactions & " " & strType
If intTransactions > 1 Then
.Subject = .Subject & "s"
End If
' Need to amend the footer depending on account being used intAccount = 2 = SSW, 3 is NPT
If intAccount = 3 Then
strFooter = Replace(strFooter, "Divisional Treasurer, Swansea South & West", "Temporary Divisional Treasurer, Neath & Port Talbot")
End If
' Now add the footer
.HTMLBody = .HTMLBody & "</table>" & strFooter
'.Importance = olImportanceHigh 'High importance
'Debug.Print strHeader
'Debug.Print .htmlbody
'Debug.Print strFooter
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
'Debug.Print objOutlookRecip.Name
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
.SendUsingAccount = objOutlook.Session.Accounts.Item(intAccount)
If blnDisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
If you do not want to hard code the number you can search for the relevant number using account name.
This is in Outlook, so you would need to modify if using in Access
Code:
Public Function ListEMailAccounts(AcctToUSe As String) As Integer
Dim outApp As Object
Dim i As Integer
Dim AccNo As Integer
Dim emailToSendTo As String
Set outApp = CreateObject("Outlook.Application")
'emailToSendTo = "xxxxxxx@gmail.com" 'put required email address
AccNo = 1
'if smtp address=email we want to send to, acc no we are looking for is identified
For i = 1 To outApp.Session.Accounts.Count
'Uncomment the Debug.Print command to see all email addresses that belongs to you
'Debug.Print "Acc name: " & OutApp.Session.Accounts.Item(i) & " Acc number: " & i & " , email: " & OutApp.Session.Accounts.Item(i).SmtpAddress
'If OutApp.Session.Accounts.Item(i).SmtpAddress = emailToSendTo Then
If outApp.Session.Accounts.item(i).DisplayName = AcctToUSe Then
AccNo = i
Exit For
End If
Next i
ListEMailAccounts = AccNo
Set outApp = Nothing
End Function
Public Function ReadSignature(sigName As String) As String
Dim oFSO, oTextStream, oSig As Object
Dim appDataDir, sig, sigPath, fileName As String
appDataDir = Environ("APPDATA") & "\Microsoft\Signatures"
sigPath = appDataDir & "\" & sigName
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFSO.OpenTextFile(sigPath)
sig = oTextStream.ReadAll
' fix relative references to images, etc. in sig
' by making them absolute paths, OL will find the image
fileName = Replace(sigName, ".htm", "") & "_files/"
sig = Replace(sig, fileName, appDataDir & "\" & fileName)
ReadSignature = sig
End Function
Called with intAccount = ListEMailAccounts("My desired account")