Link to home
Start Free TrialLog in
Avatar of snooflehammer
snooflehammerFlag for Australia

asked on

Automate forwarding emails in Outlook via a custom button

I need to automate a task in Outlook.

I need a button in an email form to open an email in a new forwarding form, change the From: field to another account and add a particular address in the To: field then send the message. This will change a 6 click & 1 keystrake operation into 1 click.

I expect this can be done with VB code assigned to a custom button the the ribbon or the Quick Access Toolbar

Thanks in advance
Avatar of Bill Prew
Bill Prew

Here's a starting place for the VBA macro that you could use to do the forward, give this a try there.  Adjust the constants near the top of the procedure.


Sub ForwardEmail()
    ' Specify from and to emails addresses
    Const ToEmail = "xxxxxxxx@zzzzzzzz.net"
    Const FromEmail = "yyyyyyyy@zzzzzzzz.net"

    ' Local variables
    Dim CurrentItem As Outlook.MailItem
    Dim Recip As Recipient
   
    ' Get the current email item to forward
    Set CurrentItem = GetCurrentItem()

    ' Forward the email
    If Not CurrentItem Is Nothing Then
        With CurrentItem.Forward
            .SentOnBehalfOfName = FromEmail
            .To = ToEmail
            For Each Recip In .Recipients
                Recip.Resolve
            Next
            .Send
        End With
    End If
End Sub

Function GetCurrentItem() As Object
    ' On Error Resume Next
    Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = Application.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = Application.ActiveInspector.CurrentItem
        Case Else
            Set GetCurrentItem = Nothing
    End Select
    ' On Error GoTo 0
End Function

Open in new window


»bp


Avatar of snooflehammer

ASKER

Thank you for your response Bill. This almost works. The message does get flagged as Forwarded & it does get sent but Exchange bounces it straight back with "You do not have the permission to send the message on behalf of the specified user"

If I do it manually, the forwarded message is received.
Please describe the process you use to do it "manually".


»bp
Open the orignal mail.

Click Forward

Click the From button and select another email account

Tab into the To field and pick the recipient from the previously typed email list

Ctrl + Enter to send
Is the new sender you want to use also an email account in that Outlook profile?


»bp
yes
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked. Good job. Thank you for your persistence
Welcome, glad that was helpful!


»bp