The MailItem.SendUsingAccount property returns or sets an Account object that represents the account under which the MailItem
is to be sent. For example:
private void SendUsingAccountExample()
{
Outlook.MailItem mail = Application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.Subject = "Our itinerary";
mail.Attachments.Add(@"c:\travel\itinerary.doc", Outlook.OlAttachmentType.olByValue,
Type.Missing, Type.Missing);
Outlook.Account account = Application.Session.Accounts["Hotmail"];
mail.SendUsingAccount = account;
mail.Send();
}
See Send a mail item by using a Hotmail account for more information.
Please remember that another account should be configured in Outlook in that case.
The SentOnBehalfOfName property makes sense only in case of Exchange profiles/accounts. Moreover, you need to have the required permissions to send on behalf of another person. See Issue with SentOnBehalfOfName for a similar discussion.
In case if you have multiple accounts configured in the profile you can use the SendUsingAccount property which allows to an Account object that represents the account under which the MailItem is to be sent.
Sub SendUsingAccount()
Dim oAccount As Outlook.account
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
oMail.Recipients.Add ("someone@example.com")
oMail.Recipients.ResolveAll
oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub