Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am looking for code to take all incoming emails to my outlook email and "copy" to my gmail acct. I originally had a script to fwd all emails, but it's a major pain to change the email address, and then the fwd info is in the body, etc. etc.

Ultimately, I would like a script to copy to another email without the fwd (or at least keeping it from the original sender instead of everything being from me) and be able to mark the email as read in my gmail acct if I read it through outlook (or both ways if that's possible)

thank you!
Posted
Comments
[no name] 30-Jul-13 8:35am    
Okay... and what have you tried? What is problem with the code that you have written?
bigazonk 31-Jul-13 8:25am    
This works. There's really no problem other than I don't want a fwd sent to my email, i want a copy. I am often not at my desk and need to reply to an email and obviously if i hit reply, it would reply to myself, but more times than not, there are several people listed on the email chain, so i would have to manually enter all names.

and i would also like to have them marked read if they are read within one or the other emails

Sub AutoForwardAllSentItems(Item As Outlook.MailItem)
Dim strMsg As String
Dim myFwd As Outlook.MailItem

Set myFwd = Item.Forward

myFwd.Recipients.Add "XXXXXXXXXX@gmail.com"
myFwd.Send
Set myFwd = Nothing

End Sub
Maciej Los 30-Jul-13 8:51am    
What version of MS Outlook?
bigazonk 31-Jul-13 8:13am    
outlook 2010
Maciej Los 31-Jul-13 8:38am    
Have you seen my answer? Have you tried to do it yourself?

1 solution

[EDIT]
Summarizing the discussion based on bigazonk's comments...

There is probably not possible to send email as another person. Why? See this: Send an e-mail message on behalf of someone else[^]

The only way is to forward a mail message. ;(

Example macro for "original forwarding", assuming that person has a permission to send mail on behalf of someone else, should looks like:
VB
Option Explicit

Sub PushMailToMe()
Dim srcMi As MailItem, dstMi As MailItem
Dim fld As Folder, att As Attachment

On Error GoTo Err_PushMailToMe

Set fld = Application.Session.GetDefaultFolder(olFolderInbox)
For Each srcMi In fld.Items
    If srcMi.UnRead = False Then GoTo SkipMail
    Set dstMi = Application.CreateItem(olMailItem)
    With dstMi
        .Sender = srcMi.Sender
        .Subject = srcMi.Subject
        .To = "mymail@domain.com"
        .CC = srcMi.CC
        .BodyFormat = olFormatHTML
        .HTMLBody = srcMi.HTMLBody & vbCrLf & vbCrLf & "Original forwarding by PushMailToMe (year: 2013)"
        For Each att In srcMi.Attachments
            .Attachments.Add att
        Next
        .Send
    End With
SkipMail:
Next

Exit_PushMailToMe:
    On Error Resume Next
    Set srcMi = Nothing
    Set dstMi = Nothing
    Exit Sub

Err_PushMailToMe:
    MsgBox Err.Description, vbExclamation, Err.Number
    Resume Exit_PushMailToMe

End Sub


Cheers!
Maciej Los

[/EDIT]
 
Share this answer
 
v4
Comments
Raja Sekhar S 1-Aug-13 2:25am    
Nice Links.... +5!
Maciej Los 1-Aug-13 2:27am    
Thank you, Raja ;)
bigazonk 1-Aug-13 9:43am    
i have tried this, but it's not showing up in the script when trying to run the rules
Maciej Los 1-Aug-13 11:41am    
It's just an example. You need to change it to your needs. I haven't access to ms outlook and can't test it by myself. Above example doesn't send any mail, it makes a copy of last mail and display it.
bigazonk 1-Aug-13 12:22pm    
ugh, ok. I'm sorry, I don't do code, so this is all confusing to me! thanks tho

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900