Gasman
Enthusiastic Amateur
- Local time
- Today, 17:35
- Joined
- Sep 21, 2011
- Messages
- 14,270
Hi all,
I now have the need to select a different email address when sending out emails.
I have rewritten my code to cater for this and failing at the SendUsingAccount.
In the debug window I have the correctly named account, however when I send the email it goes under my default email address, not the one selected for SendUsingAccount.?
I followed the logic from https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/mailitem-sendusingaccount-property-outlook
My code is below
and the correct account name is shown with the debug statement?, however I notice the Intellisense has not corrected .SendUsingAccount ?
Again, what am I missing please.?
I now have the need to select a different email address when sending out emails.
I have rewritten my code to cater for this and failing at the SendUsingAccount.
In the debug window I have the correctly named account, however when I send the email it goes under my default email address, not the one selected for SendUsingAccount.?
I followed the logic from https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/mailitem-sendusingaccount-property-outlook
My code is below
Code:
Dim OutApp As Object, OutMail As Object, OutAccount As Object
Dim strSignature As String, strBody As String, strDiv As String
Dim strGreeting As String, strTimeLimit As String
Dim iTime As Integer
strTimeLimit = "Please note, invoices should be submitted by 10 AM the following Friday to ensure prompt payment."
strTimeLimit = strTimeLimit & " Invoices received after this time will be paid the following week."
strGreeting = "Good "
iTime = Val(Format(Now(), "hh"))
Select Case iTime
Case Is < 12
strGreeting = strGreeting & "morning,"
Case Is < 17
strGreeting = strGreeting & "afternoon,"
Case Else
strGreeting = strGreeting & "evening,"
End Select
strDiv = "<div class=WordSection1>"
strBody = "<p>" & strGreeting & "</p>" & pstrMessage
' Now comes from email table
'strBody = strBody & "<p>" & strTimeLimit & "</p><p>"
strBody = strBody & "<p>Should there be any queries please let me know.</p>"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
' Need to get correct account to send on
For Each OutAccount In OutApp.Session.Accounts
If OutAccount.DisplayName = pstrCompany Then
Exit For
End If
Next
With OutMail
.Display
.To = pStrToNames
.To = "aaabbb@ccc.co.cuk"
.BCC = ""
.Subject = pstrSubject
.htmlbody = Replace(.htmlbody, strDiv, strDiv & strBody)
.attachments.Add pstrFilename
Debug.Print OutAccount.DisplayName
.sendusingaccount = OutAccount
.Send
End With
Again, what am I missing please.?