I have code that sends emails using the default Outlook account.
I tried changing the code to send from a specific email. When I run the macro, nothing happens.
Is something wrong with the code, or is it not working due to another issue (with Outlook and the accounts/permissions associated with it)?
Sub CommandButton1_Click()
Dim wb As Workbook
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim q As Long
Dim oAccount As Outlook.Account
Set wb = ThisWorkbook
For Each oAccount In Outlook.Application.Session.Accounts
    If oAccount = "theEmailiWantToUse@domain.com" Then
        For q = 2 To 3 'LastRow
            eName = wb.Sheets(1).Cells(q, 2).Value
            Set olApp = New Outlook.Application
            Set olMail = olApp.CreateItem(olMailItem)
            mailBody = "Hello, "
            With olMail
                .To = Worksheets("Emails").Cells(q, 4).Value
                .Subject = eName
                .HTMLBody = "<!DOCTYPE html><html><head><style>"
                .HTMLBody = .HTMLBody & "body{font-family: Calibri, ""Times New Roman"", sans-serif; font-size: 14px}"
                .HTMLBody = .HTMLBody & "</style></head><body>"
                .HTMLBody = .HTMLBody & mailBody & "</body></html>"
         
                Set .SendUsingAccount = oAccount
                .Display
                ' .Send
            End With
    
        Next
    Else
    End If
 
Next
    Set olMail = Nothing
    Set olApp = Nothing
End Sub
I know I have access to the email I would like to send emails from, as I can select it from Outlook and it works.