none
Auto add text to subject line for emails forwarded using rules

    Question

  • Afternoon all. I'm using Outlook 2003 and would like to set an offline rule to forward all email to an external email address. The issue is that I need to add the text "jelly welly" at the start of the subject line for a reason unknown to me?

    I'm just tring to do as I'm asked but I'll let you know when I know :-)

    Any ideas??

    Wednesday, October 03, 2012 2:52 PM

Answers

  • Then you might need to run a script in the rule.

    Try the following script sample:

    1st. add the following code sample in ThisOutlookSession in VB Editor (Press Alt+F11 to call it out)

    2nd. Modify YourName@yourDomain.com to the email address you need to forward the email to.

    3rd. create the rule to forward the emals, and enable run a script, and choose the script sample we just added.


    Private Const FORWARD_TO_EMAIL As String = "YourName@yourDomain.com"
    
    Sub ForwardEmail(MyMail As MailItem)
        On Error GoTo EndSub
        
        Dim strBody As String
        Dim objMail As Outlook.MailItem
        Dim MailItem As Outlook.MailItem
           
        Set objMail = Application.Session.GetItemFromID(MyMail.EntryID)
        
        ' Initialize email to send
        Set MailItem = Application.CreateItem(olMailItem)
        MailItem.Subject = "Jelly-Welly: " & objMail.Subject
        
        If (objMail.SenderEmailAddress <> FORWARD_TO_EMAIL) Then
        
            ' Compose email and send it to your other email
            strBody = START_MESSAGE_HEADER + Chr$(13) + _
                "From: " + objMail.SenderName + Chr$(13) + _
                "Sent: " + CStr(objMail.SentOn) + Chr$(13) + _
                "To: " + objMail.To + Chr$(13) + _
                "Subject: " + objMail.Subject + Chr$(13)
            MailItem.Recipients.Add (FORWARD_TO_EMAIL)
            
        End If
        
        ' Send email
        MailItem.Body = objMail.Body
        MailItem.Send
        
        
        ' Set variables to null to prevent memory leaks
        Set MailItem = Nothing
        Set Recipient = Nothing
        Set objMail = Nothing
        Exit Sub
        
    EndSub:
        MsgBox "Unexpected error. Type: " & Err.Description
    End Sub


    Max Meng

    TechNet Community Support

    Friday, October 05, 2012 9:58 AM
    Moderator

All replies

  • I have found out that the subject needs Jelly-Welly: for it to be authorised to go external. Has anyone ever attempted this??
    Thursday, October 04, 2012 3:19 PM
  • Then you might need to run a script in the rule.

    Try the following script sample:

    1st. add the following code sample in ThisOutlookSession in VB Editor (Press Alt+F11 to call it out)

    2nd. Modify YourName@yourDomain.com to the email address you need to forward the email to.

    3rd. create the rule to forward the emals, and enable run a script, and choose the script sample we just added.


    Private Const FORWARD_TO_EMAIL As String = "YourName@yourDomain.com"
    
    Sub ForwardEmail(MyMail As MailItem)
        On Error GoTo EndSub
        
        Dim strBody As String
        Dim objMail As Outlook.MailItem
        Dim MailItem As Outlook.MailItem
           
        Set objMail = Application.Session.GetItemFromID(MyMail.EntryID)
        
        ' Initialize email to send
        Set MailItem = Application.CreateItem(olMailItem)
        MailItem.Subject = "Jelly-Welly: " & objMail.Subject
        
        If (objMail.SenderEmailAddress <> FORWARD_TO_EMAIL) Then
        
            ' Compose email and send it to your other email
            strBody = START_MESSAGE_HEADER + Chr$(13) + _
                "From: " + objMail.SenderName + Chr$(13) + _
                "Sent: " + CStr(objMail.SentOn) + Chr$(13) + _
                "To: " + objMail.To + Chr$(13) + _
                "Subject: " + objMail.Subject + Chr$(13)
            MailItem.Recipients.Add (FORWARD_TO_EMAIL)
            
        End If
        
        ' Send email
        MailItem.Body = objMail.Body
        MailItem.Send
        
        
        ' Set variables to null to prevent memory leaks
        Set MailItem = Nothing
        Set Recipient = Nothing
        Set objMail = Nothing
        Exit Sub
        
    EndSub:
        MsgBox "Unexpected error. Type: " & Err.Description
    End Sub


    Max Meng

    TechNet Community Support

    Friday, October 05, 2012 9:58 AM
    Moderator