I need to send message from the certain E-mail address (E-mail Distribution Group) with VBA code. I have permission "Send as" and I can do it by hands, changing field "From".
Use SentOnBehalfOfName, and as long as your Exchange account has SendAs permission for the shared mailbox or distribution group, it will be sent from the shared account or group, not sent on behalf of.
If you want to send from another account in your Account list, you'll use SendUsingAccount and select the account by index or by name. See Macros to send message using the default account or a specific account for code samples.
SendAs an address code Sample
Note: this macro is used with Exchange account to send from addresses you have SendAs permissions.
Sub CustomMailMessage() Dim OutApp As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Recipient Dim Recipients As Recipients Set OutApp = CreateObject("Outlook.Application") Set objOutlookMsg = OutApp.CreateItem(olMailItem) Set Recipients = objOutlookMsg.Recipients Set objOutlookRecip = Recipients.Add("alias@domain.com") objOutlookRecip.Type = 1 objOutlookMsg.SentOnBehalfOfName = "sales@domain.com" objOutlookMsg.Subject = "Testing this macro" objOutlookMsg.HTMLBody = "Testing this macro" & vbCrLf & vbCrLf 'Resolve each Recipient's name. For Each objOutlookRecip In objOutlookMsg.Recipients objOutlookRecip.Resolve Next 'objOutlookMsg.Send objOutlookMsg.Display Set OutApp = Nothing End Sub
More Information
Send E-mail with VBA code from [E-mail Distribution Group] if I have "Send as"
_MailItem.Sender property
Any idea how I can get emails sent using SentOnBehalfOfName to appear in the 'on behalf of' account's sent folder instead of my personal sent folder?
In other words, when I manually send an email and change the From field, the sent email appears in the Sent folder of the From account. However, when I send an email using VBA, the email appears in my Sent folder. Is there a way to change this?
Hi,
I have two accounts in Outlook. My own account is called TWojcicki@MyDomain.com and the other which is my team account which is called MyTeam@MyDomain.com. I have a list of my team members in an XLSX file that I would like to send a message to.
I need to send different information to everyone on my list. I have prepared the file accordingly, each line contains a set of information needed to create an email.
The problem is that I would like to send these messages from the team account MyTeam@MyDomain.com and not from my personal TWojcicki@MyDomain.com. Meanwhile, following the instructions described by you, emails are still sent from my personal account TWojcicki@MyDomain.com.
I mean the line:
OutlookMailitem.SendUsingAccount = OutlookApp.session.accounts.Item(2) ' Item(2) refers to my team account MyTeam@MyDomain.com
What could my mistake be?
Is it possible to change the address of the person sending the email? Change antoine@mydomain.com to anonymous@mydomain.com?
Thanks for your answer.
You can type a from address in the new message field and you can change the address on the account in the Control panel -
Go to File > Account Settings > Manage Profile or open Control Panel - find Mail (Microsoft Outlook).
Click Email accounts then double click on the account - change the address at the top of the dialog - the address you use to log in is at the bottom.
Hi,
How do I change Send As permissions so that I can send mail through VBA with an email address I do not currently have Send As permission?
The email admin needs to change the permissions on the mailbox to give you send as permission in the Exchange admin portal.
and to add to my last comment because it wont let me, select a different email signature?
Hi Diane,
Is there a way to launch an oft template with the from address prefilled?
Yes... if you are using a macro to open the template, you can set the From address before displaying the template. There are macro solutions under this section:
https://www.slipstick.com/outlook/hyperlink-templates/#toolbar - they don't include the code to change the from account, but it needs to go before opening the template.
newItem.SentOnBehalfOfName = "sales@domain.com"
newItem.Display
so it would look something like this?
Yes, try that. If it doesn't work, Try this line instead, where the number is the order the accounts are in the Account Settings list.
newItem.SendUsingAccount = olNS.Accounts.Item(1)
Hi ive currently made a login register which works well. when someone adds in their details to the userform and submits a new login request or change it sends an email notification to the person currently in control. this currently sends from my default outlook work email. (MarkP@Example.com.au) i need this to be changed to send from a different email thats in my outlook as my main one is getting spammed with requests and theres now 3 registers. how can i add in a FROM field? so it sends from LoginRegisters@Example.com.au instead of my main email my code below Private Sub cmdEdit_Click() Dim xOutApp As Object Dim xOutMail As Object Dim msgvalue As VbMsgBoxResult On Error GoTo myerror msgvalue = MsgBox("Do you want To save the data?", vbYesNo + vbInformation, "confirmation") If msgvalue = vbNo Then Exit Sub If ValidateEmptyEntries() = True Then Call Edit Call reset Else Err.Raise 600, , "duplicate validation failed or empty field must be filled" End If cmdEdit.Enabled = False cmdSubmit.Enabled = True txtUser.Enabled = True 'email notification Set xOutApp = CreateObject("Outlook.Application") Set xOutMail = xOutApp.CreateItem(0) With xOutMail .To = "MarkP@example.com.au" .CC = "" .BCC = "" .Subject = "WMS LOGIN REGISTER" .Body = "Account Update Requested By… Read more »
This should work -
With xOutMail
.SentOnBehalfOfName = "sales@domain.com"
.To = "MarkP@example.com.au"
.CC = ""
Can this be tweaked to change the address when responding or forwarding if the address is in the To or CC fields? e.g. if the email was addressed to user@email.com then the From address when responding would automatically change to user@email.com (with SendAs permission).
Yes, it can be tweaked.
https://forums.slipstick.com/threads/99391-change-from-address-based-on-to-or-cc-address/