Consider this situation: in my outlook I have two accounts my_name#gmail.com (default) and my_nyme#hotmail.com . If someone sends one e-mail message to booth my addresses I’ll end up with two email in my outlook inbox. Is it possible (using VSTO for Outlook) to differentiate which email message was received for gmail.com domain and which for yahoo.com?
I have this
String emailAddress = Globals.ThisAddIn.Application.Session.CurrentUser.Address;
but it's always my_name#gmail.com. If I iterate Outlook.MailItem.Recipients I’ll get booth my email address and can’t resolve which of them is true recipient.
Use the MailItem.SendUsingAccount property - it will point to the account used to receive the message.
Related
I have a macro I wrote (with help from this site!) which searches my Inbox and removes [External] tags from email Subjects. When I run it, it seems to be working as I can see that it removes the tags in real time. I'll then reply to the email and bcc myself. The problem is that when I sort by Subject, Outlook separates all of my bcc emails from the external emails, as though their Subjects are not the same (even though they look identical in Outlook).
So, I checked the source on a bcc email and an external email that has had the macro run on it. The bcc email's source shows the Subject as I'd expect with no [External] tag. The external email's source shows the original email with [External] tag (even though Outlook's GUI shows the Subject to have no [External] tag). Farther down the bcc email's source shows the email I replied to (the original email) to have [External] in the Subject, as though it was never removed.
It's like the [External] removal only worked on my reply with regards to sorting. Any ideas on what's happening here? Why is Outlook showing an altered Subject, but not actually changing the source? What's the point?
Macro code snippet:
If InStr(1, myitem.Subject, "[External] ") > 0 Then
myitem.Subject = Replace(myitem.Subject, "[External] ", "")
myitem.Save
Outlook GUI view after running macro:
FROM SUBJECT
Me RE: Test Email
Original Sender RE: Test Email
Bcc email reply Subject source:
<br><b>Subject:</b> RE: Test Email
(Bcc reply email body)
<br><b>Subject:</b> RE: [External] RE: RE: Test Email
(Original email body)
Original external email Subject source:
<br><b>Subject:</b> RE: [External] RE: RE: Test Email
(Original email body)
Outlook sorts/groups on the PR_CONVERSATION_INDEX MAPI property (DASL name http://schemas.microsoft.com/mapi/proptag/0x00710102). Try to preserve it - read it (MailItem.PropertyAccessor.GetProperty) before resetting the Subject property and set it back (MailItem.PropertyAccessor.SetProperty) afterwards.
On a domino-built website I have a button that runs a lotusscript agent. Part of this agent sends emails out. Below is summary code/snippet to give you the idea of what I am doing
(only relevant lines of code):
dim sendtoString as string
dim sendtoArray as variant
sendtoString = "mailaddress1,mailaddress2" '<----- two email addresses in a string
sendtoArray = split(sendtoString,|,|)
maildoc.sendto = sendtoArray
maildoc.save(true,true) '<--- so I can look at it as a saved document
'maildoc.send(false) '<----- NOTE as of right now I am not sending, choosing to simply look at the saved version until I get this right
The strange thing is TWO documents are SAVED. I have not enabled the "send" line yet because I do not want multiple emails to be sent from the code, instead hoping the router will do this for me.
Maybe the send is going to work fine, and individuals will NOT receive multiple emails (if six email addresses are in the original string, I dont want six emails landing in each person's inbox).....and maybe I need to use the "SaveMessageOnSend" property instead.
Anyone have any insight on what is going on here?
Using LotusScript, you can generate and send email messages. When creating the email message, recipient email addresses must be assigned to the SendTo field. To send an email to a single recipient, simply set the object value to a valid email address. For example:
doc.SendTo = "someone#ibm.com"
However, when sending email to multiple recipients, you must create an array of values and append the values to the SendTo, CopyTo, or BlindCopyTo field(s). This can be achieved by building either a static or dynamic array of values.
For a full answer you can find on this blog: https://flylib.com/books/en/2.348.1/sending_email_to_multiple_recipients_using_lotusscript.html
VBA created emails are sent successfully, however I can only send from the email address of the default account.
As I have a few Office 365 connected email addresses, in Outlook 2016 I am able to manually select the 'FROM' out of the list of available connected email addresses.
In Outlook VBA, there is only one account (the exchange of Office 365), so using SendUsingAccount will find the one account.
SentOnBehalfOfName bounces on security issues. Is it possible to define the 'FROM' email address?
Yes, you can, but you need to create the different accounts in Outlook. When done, use this code excerpt:
Dim SendAccount As String
SendAccount = "MyDesiredAccountName"
Set MAPISession = objOutlook.Application.Session
Set MAPIMailItem = objOutlook.CreateItem(olMailItem) 'Create a new mail message
'**********************************************
'* Find desired from-account
'* If not found, use default
'*
For Each Account In MAPISession.Accounts
If Account = SendAccount Then
MAPIMailItem.SendUsingAccount = Account
Exit For
End If
Next
Is this enough to get you started?
I am working on an activity facility which stores incoming and outgoing emails in the database for different contacts. I do this by looping through each folder in my namespace and restricting emails based on the sender email address.
I have managed to store incoming emails so far, but outgoing emails are completely ignored for some reason. I am assuming I am doing the "Mailtiems.Restrict" incorrectly, however I could not figure out what it may be. Please see the code below:
If folder.Name = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail).Name Then
outlookItems = folder.Items
outlookItems = outlookItems.Restrict("[SenderEmailAddress] = " & Quote(txtContactPersonalEmailAddress.Text) & " AND [MessageClass] = 'IPM.Note'")
' Count total folder items for progress bar
iOutlookFolderTotalMailItems = outlookItems.Count
The count always returns 0 even though I have sent an email to this contact and it appears in my "Sent Items" folder. I wonder if there is a different property I will need to use for "Sent Items" other than "SenderEmailAddress".
If you are searching for the recipients rather than the sender, you should not be specifying SenderEmailAddress - the sender will always be you.
See Filter sent items outlook by address in Excel VBA
I am using Excel 2010 on W7 x64, to send email from Outlook using code from Ron de Bruin. I have an individual and group email address that I send from.
I want to send from the group address by changing it in VBA.
The secondary address is not set up as an actual account in Outlook. If I go to File - Account Settings in Outlook, there is only one email account listed.
The group email address simply forwards to the group.
I created an actual account for the group box.
I added the reference to Microsoft Outlook Object Library in VBA, and added the code to select between account 1 or 2 using the MailItem.SendUsingAccount property, but Outlook would freeze up when trying to send from this address.
I can manually select between my Individual and Group email in the from dropdown box in Outlook when I send emails.
Is there a way to do this in VBA without setting up a second account?
You can use .SentOnBehalfOfName property of outlook to send mail in the name of other user.
Check the following code and URL for further details: http://www.slipstick.com/developer/code-samples/send-email-address-vba/
oMail.SentOnBehalfOfName = "user#domain.com"
SendUsingAccount worked for me.
For Each acc In OutApp.Session.Accounts
If acc = frmMain.cmbxSendFrom.Text Then
.SendUsingAccount = acc
End If
Next acc