0

Thanks in advance. The scenario is: When a new email is created containing an address pre-populated in the "To" field then clicking a custom form button, copy that email into the custom form's "To" field and close the original new email. (essentially replacing the original regular email with the form pre-populated with the original "To" address).

The Custom form is working fine but I'm confused on how to talk to or pull the data from that first email to the form when the form opens.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
MichaelM
  • 3
  • 1

2 Answers2

0

Loop through the MailItem.Recipients collection, read each recipient's Name and Address property, call MailItem.Recipients.Add on the new message. In case of SMTP addresses, pass "Name " to Recipeints.Add, in case of EX addresses pass just the EX address.

You can also try to read PR_ENTRYID, PR_DISPLAY_NAME, PR_EMAIL_ADDRESS properties using Recipient.PropertyAccessor and set them on the new message using Recipient.PropertyAccessor.SetProperty to make sure the recipients are resolved and look exactly like the original message.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thank you for helping, forgive me for being naive, doesn't MailItem.Recipients refer to vals in the Address book? I just need to scoop whatever the address is from the empty opened email (example generated by clicking a "mailto:" link in an HTML doc (no address book involved)). Then using a button in the "Quick Access Toolbar" on that newly opened email, trigger my custom form & copy the email address to the "To:" field form, then close the original "mailto" generated blank email.(easy solution is to just copy/paste into the form, but client doesnt want to do that work.) – MichaelM Apr 06 '14 at 16:20
  • A recipient can refer to either an entry in the adders book (e.g. a GAL entry or one of the contacts in the Contacts folder) or a one-off address entry. In the latter case the recipient entry id embeds the email address, its type, and the display name. – Dmitry Streblechenko Apr 07 '14 at 16:29
0

I've modified the Macro that opens my custom form. I've added a button to the quick launch toolbar that appears on every email. The Macro gets the address in the To field of email #1, launches the custom form, places the address into the To field of the custom form, then closes the original (email #1).

Public Sub ComplexCustomForm()
 Dim olfolder As Outlook.MAPIFolder
 Dim olapp As Outlook.Application
 Dim Items As Outlook.Items
 Dim Item As Object
 Dim m As mailItem

 Set m = ActiveInspector.CurrentItem
 f = m.To
 Set olapp = CreateObject("Outlook.Application")
 Set olfolder = olapp.GetNamespace("Mapi").folders("SHARED FOLDER WHERE IPM.Note RESIDES")

 Set Items = olfolder.Items
 Set Item = Items.Add("IPM.Note.ComplexCustomForm")
 Item.Display
 Item.To = f
 m.Close olDiscard

 Set m = Nothing
 Set olfolder = Nothing
 Set olapp = Nothing
 Set Items = Nothing
 Set Item = Nothing
End Sub
MichaelM
  • 3
  • 1