I'm currently developping a program that will serve to send emails via company's EWS. the code for sending the message works perfectly but i also need to get some data about the sender of the email. It means, when a user sends the email to me, I need to see his position and address.
I'm struggling for more then a week to find a way to define the sender in the code and his contact details. And still nothing found so far.
Will appreacite your helf.
My code so far:
Dim url As String = "https://.../ews/Exchange.asmx"
exch.Url = New System.Uri(url)
exch.UseDefaultCredentials = False
exch.Credentials = New System.Net.NetworkCredential(TextBox2.Text, TextBox1.Text)
' exch.AutodiscoverUrl("myemail")
'exch.ResolveName("", ResolveNameSearchLocation.ContactsThenDirectory, True)
Dim message As New EmailMessage(exch)
message.Subject = "Новое заявление (АП) - " & ComboBox1.SelectedItem
message.Body = "Добрый день!" & vbNewLine & vbNewLine & "Прошу обработать заявление - " & ComboBox1.SelectedItem
For Each f In attfiles
message.Attachments.AddFileAttachment(f)
Next
message.ToRecipients.Add(email)
message.SendAndSaveCopy()
You are on the correct path by using the ResolveNames operation. Using the sender SMTP address, use ResolveNames to get back a list of potential matches for the sender. The foreach in the example is just so you can see each result. Since you are passing an SMTP address, it is very likely that your result set may be no more than a few contacts.
It sounds like one of your assumptions is that the sender always has an entry in the user's Contacts folder. Is that always true? Can the sender not exist as an entries in the recipients Contact folder but have an entry in Active Directory? You are doing the right thing to cover both possibilities by using the ResolveNameSearchLocation.ContactsThenDirectory option.
Resolve names works well if you have a display name or SMTP address. You also ask about how to find a specific contact. You mention that want to search the Contacts folder, but you are concerned about the number of employees. Do all employees have contact items in the target mailboxes? To search for specific contacts, learn about EWS search.
Related
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
I created a makro in excel to send all TODOs to the responsible people. Now I want to add the sender address into the CC. I know how to set the CC but I don't know how to get the current sender address.
Set session = CreateObject("Notes.NotesSession")
Set db = session.GETDATABASE("", "")
Call db.OPENMAIL
Set doc = db.CREATEDOCUMENT
Call doc.REPLACEITEMVALUE("CopyTo", strEmail)
I think it should work with the notes session, but I didn't find any method for this.
You can just use NotesSession.UserName(). This is Notes mail you are sending. You don't need a full SMTP-style address with the # and the DNS domain name. You can just put the user's Notes username in an addressing field and the Domino router will do the lookup and it will just work.
The above is true as long as (a) the server that you have established the session with is either the user's home mail server, a member of the same Notes domain (which is not the same thing as a DNS domain), or a member of a Notes domain that includes the user's Notes domain as part of its Directory Assistance (or its cascading address book list if it's using 20-year-old configurations), and (b) the username is unique within the above scope.
another suggestion, copy sender from last sent mail, to test
Set view = db.GetView("(($Sent))")
Set sentdoc = View.GetLastDocument
sender=sentdoc.getItemValue("From")
The way I automated Lotus Notes and sending emails was using this site below:
Send files using Lotus Notes
The area you want to pay attention to is at the bottom, which takes "noDocument" and adds the relevant titles "Subject", "to", "Sendto" etc.
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = vaRecipients
.CopyTo = vaCopyTo
.Subject = stSubject
.Body = vaMsg
.SaveMessageOnSend = True
.PostedDate = Now()
.Send 0, vaRecipients
End With
Use NotesSession.userName() to get the current username. If you really want the full email address you might also be able use #namelookup formula.
However, I would stay away from accessing notes via COM as it does not work on 64bit and IBM couldn't care less about it. I had several excel files which used this handy technique, but they are all broken since we moved to 64bit. Check this old kb https://www-304.ibm.com/support/docview.wss?uid=swg21454291
(Running on Win 8.1)
The ultimate goal is the answer to this question:
Using VBA in Outlook 2013, how can I examine incoming RSS posts for contained keywords?
The details so far:
As per this page: http://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/ (first paragraph after the initial quote), it is possible to have a VBA script in Outlook 2013 to process PostItem arguments.
RSS feeds provide a PostItem argument, as in
Public Sub ScanRSSPost(Item As Outlook.PostItem)
...
End Sub
However, the rules wizard won't show this procedure.
Other procedures processing mails coming in and having a MailItem argument as in
Sub AddMailToOPQueue(oMail As Outlook.MailItem)
...
End Sub
are displayed as selectable scripts in the wizard and work as expected.
Is the lady simply wrong, or am I overlooking a setting of which I am not aware?
You cannot process incoming RSS items the way Application.NewMailEx lets you process new messages, but you can still use Items.ItemAdd event on the folder corresponding to a particular RSS feed.
I found that the claim in the quoted post simply does not work.
If you have the same question, here is a work-around:
(1) In Outlook, create a new rule: on receiving any feed (or the particular one you are interested in), forward it to your mail address (I created a dedicated one to keep things clean and uncluttered), and process no further rules.
(2) On the receiving mail address, create a new rule calling a script like this:
Sub AddMailToOPQueue(oMail As Outlook.MailItem)
...
End Sub
In the routine, the forwarded RSS posts' oMail.Body property will start with: blank, vbCrLf, blank, vbCrLf, "Feed: ", so to extract the feed in question, you can use something similar as:
If Left(sBody, 12) = " " & vbCrLf & " " & vbCrLf & "Feed: " Then
sFrom = Mid(sBody, 13)
sFrom = Left(sFrom, InStr(sFrom, vbCrLf) - 1)
'sFrom has the feed name now. The post's subject is in oMail.Subject.
...
End If
(3) In Outlook, create another rule for the addressee, on receiving items executing above script, which will be selectable in the wizard.
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 have generated a rule which then actions a SCRIPT.
I want to get details from the identified email message - i.e. the body then output to a file that can be read elsewhere.
My logic sort of works but I am currently retrieving the contents of the selected or highlighted email rather than the email identified by the rule.
INFO ONLY
[Specifically the email is a FOREX Signal with a defined Subject. I then want to get the contents of this email to a file that can subsequently be read by an Expert Advisor running on a MetaTrader 4 platform]
struggled to get meaningful tags accepted - i.e. script or OutlookRules
You pass the mailitem as a parameter.
If, for example, you pass Item then process Item.
Sub CustomMailMessageRule(Item As Outlook.MailItem)
MsgBox "Mail message arrived: " & Item.Subject
End Sub