Is there a way to move sent emails from the sent folder to another folder if it's sent to a certain address. Outlook rule editor for Outlook-2010 only allows to Move AND Copy when choosing to apply rule to messages that have been sent. (while messages received allows for only moving.)
The SaveSentMessageFolder property of the MailItem class allows to set a Folder object that represents the folder in which a copy of the e-mail message will be saved after being sent. So, the message will be placed to the correct folder.
Sub SetSentFolder()
Dim myItem As Outlook.MailITem
Dim myResponse As Outlook.MailITem
Dim mpfInbox As Outlook.Folder
Dim mpf As Outlook.Folder
Set mpfInbox = Application.Session.GetDefaultFolder(olFolderInbox)
Set mpf = mpfInbox.Folders.Add("SaveMyPersonalItems")
Set myItem = Application.ActiveInspector.CurrentItem
Set myResponse = myItem.Reply
myResponse.Display
myResponse.To = "Eugene Astafiev"
Set myResponse.SaveSentMessageFolder = mpf
myResponse.Send
End Sub
Related
Is it possible to create a new email with redemption and open outlook new email dialogue, without outlook running.
I know how to create an email, is it just a case of creating the temporary email save it as an msg, then process start, or can I achieve this via another method.
Dim Session As RDOSession = RedemptionLoader.new_RDOSession
Dim Msg = Session.GetMessageFromMsgFile(strPath & "" & strFilename, True)
Msg.MessageClass = "IPM.Note"
You can, just call RDOMail.Display(true/false) (true for for modal display). Keep in mind that MAPI forms used to show the message are implemented by outlook.exe, so it will launch anyway if it is not running.
You can create new items without Outlook running on the system (but it should be installed with a mail profile configured, or at least the MAPI runtime should be installed):
' create a new session
Dim Session As RDOSession = RedemptionLoader.new_RDOSession
Session.Logon
Set Folder = Session.GetDefaultFolder(olFolderInbox)
Set Msg = Inbox.Items.Add("IPM.Note")
Msg.BCC = "eugene#astafiev.vvv"
Msg.Subject = "test"
Msg.Display()
Accounts
Let's say I have multiple accounts in Outlook ("bob#example.com" and "bob#gmail.com"):
Mailboxes
Each account can have multiple mailboxes. In this case the account bob#example.com has 3 mailboxes:
"bob#example.com"
"Example Support"
"Online Archive - bob#example.com"
and the account bob#gmail.com only has 1 mailbox:
"bob#gmail.com"
The screenshot is after [right clicking "Example Support" > Data File Properties... > Advanced]
The mailbox "Example Support"
This is the mailbox I'm interested in. It has the email address "support#example.com".
Find Outlook.Store by it's email address
I know how to find the Outlook.Store object for the mailbox "Example Support", given only it's email address:
Function GetStore(oApp As Outlook.Application, emailAddress As String) As Outlook.Store
Dim oStore As Outlook.Store
Set oStore = Nothing
Dim s As Outlook.Store
For Each s In oApp.Session.Stores
If s.ExchangeStoreType = olExchangeMailbox Then
Dim PR_MAILBOX_OWNER_ENTRYID As String
PR_MAILBOX_OWNER_ENTRYID = "http://schemas.microsoft.com/mapi/proptag/0x661B0102"
Dim ownerEntryId As String
ownerEntryId = s.PropertyAccessor.BinaryToString(s.PropertyAccessor.GetProperty(PR_MAILBOX_OWNER_ENTRYID))
Dim oAddressEntry As Outlook.AddressEntry
Set oAddressEntry = oApp.Session.GetAddressEntryFromID(ownerEntryId)
Dim oExhangeUser As Outlook.ExchangeUser
Set oExhangeUser = oAddressEntry.GetExchangeUser()
If oExhangeUser.PrimarySmtpAddress = emailAddress Then
Set oStore = s
Exit For
End If
End If
Next s
Set GetStore = oStore
End Function
Question
How do i find the Outlook.Account object of a mailbox, given only the email address of that mailbox?
Details
I can see the Outlook.Account object with .SmtpAddress "bob#example.com" that i want, in the debugger. But, i can't find any relation between it and the mailbox for "Example Support", unlike in the screenshot.
The Outlook.Store object for the mailbox "Example Support", is not the .DeliveryStore for the Outlook.Account object with .SmtpAddress "bob#example.com".
Essentially, you need to find PR_SERVICE_UID of the profile section where the store account properties are stored. Once you have that, you can look through all accounts (IOlkAccountManager) and check if you can find a matching IOlkAccount object with the same value of the PROP_MAPI_SERVICE_UID property. You can see these (and other) objects in OutlookSpy.
You can do that in C++ or Delphi, but not in VBA or VB6 since it requires Extended MAPI.
If using Redemption (I am its author) is an option, it exposes the IRDOStore.StoreAccount property. You can also start with an RDOAccount object (exposed in the RDOSession.Accounts collection), cast it to RDOExchangeAccount, and loop through the IRDOExchangeAccount.AllStores collection.
set oomStore = Application.ActiveExplorer.CurrentFolder.Store
Set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set redStore = Session.GetRDOObjectFromOutlookObject(oomStore)
set redAccount = redStore.StoreAccount
Debug.Print "Store account name: " & redAccount.Name
Debug.Print "All account stores:"
for each otherStore in redAccount.AllStores
Debug.Print otherStore.Name
next
There is no direct correlation between accounts and stores except delivery stores. You even can add a new store to the profile at runtime, see Add or remove a store for more information.
The best what you could do is to try to retrieve a shared store by using the GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user. Getting the Parent property value can lead you to the store.
Can anyone help me with excel vba code to send multiple/specific emails that are present in my inbox as an attachment in a new mail to someone I want.
so basically what I am asking for is if I go to my outlook express inbox and select lets say three mails and then click on the forward button on the ribbon it will create a new mail item with the mails that were selected as an attachment. I want this to be automated from excel vba.
Please any help will be highly appreciated.
Regards,
Premanshu
I have found answer for my question after some more search from one online forum/community and have been able to modify that according to my need. Posting the code below for anyone's reference and also the link for the original post that I used and modified for my purpose.
Sub ForwardSelectedItems()
On Error Resume Next
Dim myolApp As Outlook.Application
Dim objItem As Outlook.MailItem
Set objOL = CreateObject("Outlook.Application")
If objOL.ActiveExplorer.Selection.count = 0 Then
MsgBox ("No item selected")
Exit Sub
End If
For Each objItem In objOL.ActiveExplorer.Selection
Set objMsg = objItem.Forward()
With objMsg
.Display
For Each itm In objOL.ActiveExplorer.Selection
.Attachments.Add itm, olEmbeddeditem
Next itm
.Subject = "example"
.To = "example#example.com"
.Body = “”
.Send
End With
Exit For
Next
Set objItem = Nothing
Set objMsg = Nothing
End Sub
the link for the popst I refered to is:-
Forwarding Outlook Item as attachment and adding it to a category in the same VBA macro
Thank you all.
Regards,
Premanshu
I need to write a formula that recognizes when someone's birthday is and trigger www.zapier.com.]
I have a birthday-recognition formula that creates a "send email" hyperlink, but I need it to be automatically sent (and delayed to 10am) non-interactively. I also did something in VBA but I only managed to write code that sends that message to 1 person.
Here's the working birthday-recognition formula. Client names are in column C8:C100, emails are in D8:D100, DOBs are in E8:E100 and the "send mail" hyperlinks are in F:100.
=IF(TEXT(E13;"d.m")=TEXT(TODAY();"d.m");HYPERLINK("mailto:"&D13&"? subject="&$D$2&"&body="&SUBSTITUTE(SUBSTITUTE($E$3;"$";C13);"#";$D$4);"pošalji čestitku");"")
"pošalji čestitku" = send mail (croatian language)
VBA code:
Private Sub CommandButton1_Click()
POŠALJIROĐENDANSKEČESTITKE
End Sub
Public Function POŠALJIROĐENDANSKEČESTITKE()
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = Cells.Range("D8:D1000")
olMail.subject = "Sretan rođendan"
olMail.Body = "Poštovani," & vbCrLf & vbCrLf & "Želimo Vam sretan rođendan"
& vbCrLf & vbCrLf & "Sve najbolje," & vbCrLf & vbCrLf & "svinaweb"
olMail.Send
End Function
This code just sends the message to one email when I click on the command button, but as I said I want it to be sent to every person that has a birthday today and to delay the sending of the emails to 10am instead of midnight.
I am using Excel 2013.
The Recipients property of the MailItem class returns a Recipients collection that represents all the recipients for the Outlook item.
The Recipients class provides the the Add method to create a new Recipient object and add it to the Recipients object. The Type property returns or sets the type of recipient. It can be one of the following OlMailRecipientType constants: olBCC, olCC, olOriginator, or olTo.
So, you can send the single email to all people. You just need to add them to the Recipients collection. Or, if you need to have individual message bodies, you can create separate email messages.
The DeferredDeliveryTime property of the MailItem class allows to set a Date indicating the date and time the mail message is to be delivered.
I'm looking for kind of the opposite of creating a rule to auto-forward
emails. I want to create a rule that acts on RECEIVED auto-forwarded emails,
but not any that were manually forwarded or replied to by the same person.
E.g. Jim forwards me all emails with "blah" in the subject, and I want to
move those auto forwards to my "Jim's auto-forwards" folder, but if he
forwards me a message manually that says "blah" but he adds his own comments,
I want it to stay in my inbox.
Outlook seems to know that it is auto forwarded, as it shows up
as such when you view the email. Just above the "From" section but
just below the ribbon, it says something like:
"This message was AutoForwarded."
However I haven't found any option to create a rule filtering these.
Our exchange server (Outlook maybe?) adds the following headers when auto-forwarding:
Auto-Submitted: auto-generated
X-MS-Exchange-Generated-Message-Source: Mailbox Rules Agent
(Visible by opening an email and viewing the message "Properties" to see the headers) These appear to be what Outlook is using to detect that a message was AutoForwarded (or at least coincide)
And Outlook/Exchange 2013 has the filter option "with specified words in the message header"
I have used a rule that looks similar to the following to successfully move only "blah" subject messages autoforwarded from "Jim" to a specific folder:
Apply this rule after the message arrives
from 'jim#example.com'
and with 'blah' or 'blurg' in the subject
and with 'auto-generated' or 'Auto-Submitted' in the message heade
move it to the 'Jims auto-forwards' folder
And this has appeared to prevent any that he's manually forwarded from being processed by the same rule.
Our Exchange Server adds the following header for Auto Forwarded and Auto Replies
X-MS-Exchange-Inbox-Rules-Loop: abc#company.com
where abc#company.com is the email of the person auto forwarding the email.
I use MS Outlook 2010 in which i have setup a rule ->
From: abc#company.com
and with 'X-MS-Exchange-Inbox-Rules-Loop: abc.xyz#company.com'
or 'X-MS-Exchange-Inbox-Rules-Loop: abc.XYZ#company.com' in the message header
move it to the 'xyz' folder
i have checked abc.xyz#company.com as well as abc.XYZ#company.com in message header as in some auto Fwd/Re email header the Lastname of the sender was uppercase.
Note: as mentioned before this rule applies to all Auto Forwarded and Auto Replies (e.g Out of office/ vacation auto replies) from that person. Manual Fwd/RE emails are not filtered
I do not think rules can do this.
Try some VBA. untested
Edit 2013 02 26
Put the code in ThisOutlookSession http://www.slipstick.com/outlook-developer/how-to-use-outlooks-vba-editor/
Here are some references so you can debug if necessary.
NewMailEx: http://msdn.microsoft.com/en-us/library/office/bb147646(v=office.12).aspx
AutoForwarded Property: http://msdn.microsoft.com/en-us/library/office/ff867162.aspx
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim varEntryIDs
Dim objItem
Dim i As Integer
Dim myOlApp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
varEntryIDs = Split(EntryIDCollection, ",")
For i = 0 To UBound(varEntryIDs)
Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))
'Debug.Print "NewMailEx " & objItem.Subject
If objItem.SenderName = "Jim Smith" Then
If objItem.AutoForwarded then
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
' Assumes destination folder is directly under the Inbox
Set myDestFolder = myInbox.Folders("Jim AutoForwarded")
objItem.Move myDestFolder
End If
End If
Next
Set objItem = Nothing
Set myDestFolder = Nothing
Set myInbox = Nothing
Set myNameSpace = Nothing
End Sub