Sending Outlook Msg via VBA, but having the 2nd Outlook account in the from.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
758
Hello friends, Hope all is well! Please help adjust the code.

I have two outlook accounts, one for me, the other is for the MIS Dept. I wish to send outlook msgs, using the second account please.
The code below keeps only sending mail with my name. the other outlook address is secondary.

Your kind help is really appreciated!

VBA Code:
Sub SENDMAIL()
    'Add reference to Microsoft Outlook Object Library
    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(2)
    
    'Or us the name instead of the number
    Set OutAccount = OutApp.Session.Accounts("mis@drs.com")
   
ToAddress = Sheets("DB").Range("f1").Value

    'Create New Outlook Email Item to Attach Image(s)
   On Error Resume Next
    With OutMail
        .To = ToAddress
        .CC = ""
        .BCC = ""
        .Subject = "Thank you"
        .BodyFormat = olFormatHTML
           
        .Attachments.Add "C:\Users\nawaf.altaher\Downloads\avs\ssare\" & Worksheets("db").Range("E1").Value & ".png", olByValue, 0
        .HTMLBody = "<img src=""cid:" & Worksheets("db").Range("E1").Value & ".png""  width=""750"" height=""520"">"
                    
       .Display
        '.Send 'or just put .Display to check
    End With

    Set OutlookMail = Nothing
    Set OutApp = Nothing
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
VBA Code:
Sub SENDMAIL()
    'Add reference to Microsoft Outlook Object Library
    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(2)
   
    'Or us the name instead of the number
    Set OutAccount = OutApp.Session.Accounts("mis@drs.com")
  
ToAddress = Sheets("DB").Range("f1").Value

    'Create New Outlook Email Item to Attach Image(s)
   On Error Resume Next
    With OutMail
        .SentOnBehalfOfName = "secondemail@mrexcelcom"
        .To = ToAddress
        .CC = ""
        .BCC = ""
        .Subject = "Thank you"
        .BodyFormat = olFormatHTML
          
        .Attachments.Add "C:\Users\nawaf.altaher\Downloads\avs\ssare\" & Worksheets("db").Range("E1").Value & ".png", olByValue, 0
        .HTMLBody = "<img src=""cid:" & Worksheets("db").Range("E1").Value & ".png""  width=""750"" height=""520"">"
                   
       .Display
        '.Send 'or just put .Display to check
    End With

    Set OutlookMail = Nothing
    Set OutApp = Nothing
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top