简体   繁体   中英

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 Reporting@zzzz.com.

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 Reporting@zzzz.com'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)?

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

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 = "Reporting@zzzz.com"
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
SetSendingAcct olMail, strSMTP

With olMail
    .Subject = stSubject

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM