Declare Email Address to Send FROM

CorrieAnn

New Member
Joined
Sep 4, 2007
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Objectives: Auto-create and email in display mode where the FROM, TO, SUBJECT and some of the BODY are auto-populated
* FROM: AMLC@emailaddy.com
* TO: Maria@emailaddy.com
* Store copy in SENT folder for the AMLC mailbox

Problems:
* I cannot get the FROM to stop defaulting to the user's primary email address.
* A copy of the sent email keeps going into the user's SENT folder instead of the SENT folder for the AMLC mailbox

I have the following script that is launched by a user from an excel form as needed:

VBA Code:
Sub SendMariaEmail()
'
'Send email to Maria to verify PNs that are out of tolerance based on values in BOM
'
    Dim OutApp As Object
    Dim OutMail As Object
    Dim Signature As String
    Dim strFrom As String
  
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .Display
    End With
        Signature = OutMail.htmlbody
    With OutMail
'        .SentOnBehalfOfName = "[EMAIL]AMLC@emailaddy.com[/EMAIL]" <---------THIS SOLUTION SORT OF WORKS, BUT PUTS THE SENT COPY IN THE USER'S SENT FOLDER, NOT IN THE SENT FOLDER FOR THE AMLC MAILBOX
'        outlookmailitem.SendUsingAccount = OutApp.session.accounts.Item(2) <---------THIS SOLUTION DID NOT WORK AT ALL
        strFrom = "[EMAIL]AMLC@emailaddy.com[/EMAIL]" <---------THIS SOLUTION DID NOT WORK AT ALL
        .To = "[EMAIL]Maria@emailaddy.com[/EMAIL]"
        .CC = ""
        .BCC = ""
        .Subject = Range("B4") & " - BOM Details to Verify for AMLC - " & Range("B9") & ", Assembly:  " & Range("B5")
        .htmlbody = "Maria," & "<br><br>" & "Can you please verify the information below and get back to me ASAP?" & "<br><br>" & "<i>*Please note that the agreed-upon SLA for AMLCs are a 24-hour turnaround from the time Customer Service submits them for processing to the time they get them back to hand it over to Glen.</i>" & "<br><br>" & Signature
'        .Attachments.Add ActiveWorkbook.FullName
        'You can add other files also like this
        '.Attachments.Add ("C:\test.txt")
        .Display 'or use .Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

As you can see, I have tried a few different ways to get the "FROM" field populated in the email. The closest working solution was using ".SentOnBehalfOfName", though it doesn't display correctly while the email is being edited. It still shows the user's primary email address until they actually send the email. The correct email address is displayed only AFTER the email is sent.

Can someone help me do what I perceive to be a simple task (see objectives listed above)?
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
In some cases (my workplace, for example) accounts are limited due to group policy restrictions. Sending on behalf may still be allowed where you have permission to a mailbox, but it may not do everything you want it to, as you have observed. To see what's up, determine the accounts Outlook actually has:
VBA Code:
Sub subListOutlookAccounts()
    Dim n
    Dim outApp As Outlook.Application
    Set outApp = CreateObject("Outlook.Application")
    For n = 1 To outApp.Session.Accounts.Count
        Debug.Print outApp.Session.Accounts.Item(n)
    Next n
    Set outApp = Nothing
End Sub

On my work PC this is returns only one account (my own), despite being able to "see" several others and being able to choose "From" when manually drafting emails in Outlook.

On my home PC (with no group policy, thank goodness!) even though it has access to the same mailboxes (and more), all the accounts that I can "see" are listed.

In your case, the On Error Resume Next in your code is probably hiding the error regarding using outlookmailitem.SendUsingAccount = OutApp.session.accounts.Item(2) if there is only your account available. In that case it's ignored and will send from the default (i.e. your) account ... which is the result you are experiencing.

I'm not sure whether there is a solution to your issues, especially the Sent folder point. When I use .SentOnBehalfOfName it does put the email into the Sent box of the .SentOnBehalfOfName specified, but I can see no obvious code difference between what you're doing and what I have. Who knows...maybe another group policy "feature"?
 
Upvote 0
Try again but :

VBA Code:
.SendUsingAccount = OutApp.Session.Accounts.Item(2)  
.Display
 
Upvote 0
Objectives: Auto-create and email in display mode where the FROM, TO, SUBJECT and some of the BODY are auto-populated
* FROM: AMLC@emailaddy.com
* TO: Maria@emailaddy.com
* Store copy in SENT folder for the AMLC mailbox

Problems:
* I cannot get the FROM to stop defaulting to the user's primary email address.
* A copy of the sent email keeps going into the user's SENT folder instead of the SENT folder for the AMLC mailbox

I have the following script that is launched by a user from an excel form as needed:

Sub SendMariaEmail()
'
'Send email to Maria to verify PNs that are out of tolerance based on values in BOM
'
Dim OutApp As Object
Dim OutMail As Object
Dim Signature As String
Dim strFrom As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.Display
End With
Signature = OutMail.htmlbody
With OutMail
' .SentOnBehalfOfName = "AMLC@emailaddy.com" <---------THIS SOLUTION SORT OF WORKS, BUT PUTS THE SENT COPY IN THE USER'S SENT FOLDER, NOT IN THE SENT FOLDER FOR THE AMLC MAILBOX
' outlookmailitem.SendUsingAccount = OutApp.session.accounts.Item(2) <---------THIS SOLUTION DID NOT WORK AT ALL
strFrom = "AMLC@emailaddy.com" <---------THIS SOLUTION DID NOT WORK AT ALL
.To = "Maria@emailaddy.com"
.CC = ""
.BCC = ""
.Subject = Range("B4") & " - BOM Details to Verify for AMLC - " & Range("B9") & ", Assembly: " & Range("B5")
.htmlbody = "Maria," & "<br><br>" & "Can you please verify the information below and get back to me ASAP?" & "<br><br>" & "<i>*Please note that the agreed-upon SLA for AMLCs are a 24-hour turnaround from the time Customer Service submits them for processing to the time they get them back to hand it over to Glen.</i>" & "<br><br>" & Signature
' .Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub

As you can see, I have tried a few different ways to get the "FROM" field populated in the email. The closest working solution was using ".SentOnBehalfOfName", though it doesn't display correctly while the email is being edited. It still shows the user's primary email address until they actually send the email. The correct email address is displayed only AFTER the email is sent.

Can someone help me do what I perceive to be a simple task (see objectives listed above)?


Now that you mention the group policy, you may be right. Our emails and such are managed by a third party IT firm. We run into a lot of brick walls because of it.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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