Have adapted a few sample codes that I have found (below) to try and automate an email process. I need to use a specific send account, attach one or two PDF files in specified folder with file names that do not change and also check if there are not any attachments, then send nothing. This is what I have modified below that will work-for one attachment only. Note: I found several code samples for SendUsingAccount but this is the only one that would work with an attachment.
Sub mail_from_My_account() Const FILE_ATTACH As String = _ "C:\Users\Kathy\Documents\ThisFolder\Mail\PDF\Brian_I.pdf" Dim OutApp As Outlook.Application Dim OutMail As Outlook.MailItem Dim OutAccount As Outlook.Account Dim strbody As String Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(olMailItem) 'Use the first account, see that Item is 1 now Set OutAccount = OutApp.Session.Accounts.Item(5) strbody = "See Attached" On Error Resume Next With OutMail .SendUsingAccount = OutAccount .To = ActiveWorkbook.Sheets("Brian_I").Range("H1") .Subject = "Mail" .Body = strbody If Dir(FILE_ATTACH, vbNormal) <> "" Then .Attachments.Add FILE_ATTACH .Send End If End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing Set OutAccount = Nothing End Sub
I have tried a number of different methods but cannot get it to work. I'd appreciate any suggestions.