KrisErickson
KrisErickson

Reputation: 73

How to change "from" field?

I inherited an Access program that sends emails from my email address.
I want to send from a group email address, say [email protected].

There are two email boxes, mine and the group email.
I changed the default email account in Outlook to use the group email, but it deposits the emails into my draft folder instead of [email protected]'s draft folder.

The code uses this to make an email:

Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
With olMail
    .Subject = stSubject

olMail does not appear to have a .From field.

How can I change the from field or get the macro to recognize the 2nd email box (which I have full rights to)?

Upvotes: 0

Views: 4028

Answers (2)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

Is that a delegate Exchange mailbox? Try to set MailItem.SentOnBehalfOfName property.

Upvotes: 2

pteranodon
pteranodon

Reputation: 2059

I have dealt with this in a non-delegate situation -- multiple accounts (Exchange, IMAP). Any MailItem I created was coming from my Exchange account, even though the IMAP account was set as the default to send from. If you declare this sub:

Sub SetSendingAcct(ByRef mi As Object, strAddress As String)
' mi as Outlook.MailItem

Dim acct As Object 'Outlook.Account
For Each acct In appOutlook.Session.Accounts
    If acct.SmtpAddress = strAddress Then
        Set mi.SendUsingAccount = acct
        mi.Display
        mi.Save ' This makes the change visible in the UI
        Exit For
    End If
Next acct
End Sub

Then you would change your code to:

Dim strSMTP = "[email protected]"
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
SetSendingAcct olMail, strSMTP

With olMail
    .Subject = stSubject

Upvotes: 2

Related Questions