Microsoft Graph API - find message by internetmessageid - email

I need to find conversationId for email exchange between two user - John and Harry.
In my scenario:
John sends message to Harry.
I have email metadata from email that John has sent, e.g. converstationId, internetMessageId, messageId (m$ graph user specific).
Now I would like to reply from Harry. Unfortunately the converstionId of Harry is different then John, so I can't use it. What I would like to do is to find email message object in Harry's inbox and use his conversationId.
With valid converstationId, I would be able to call replyAll on Harry behalf.
Can I make call like:
GET /me/messages?$filter=internetMessageId eq abcd

Yes, you can make a GET call in the form you suggest - have you tried it? The graph API supports standard ODATA query parameters.
On the graph API explorer, the following call works for me:
https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq '<1430948481468.34600#THCIE7Dev2.onmicrosoft.com>'

This works
https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq '<1430948481468.34600#THCIE7Dev2.onmicrosoft.com>'
BUT
One must URL encode the internetMessageId
Thus
https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq '%3C1430948481468.34600%40THCIE7Dev2.onmicrosoft.com%3E'

Related

download only the new content in email reply by google gmail api

I am trying to access Gmail messages via google API.
https://developers.google.com/gmail/api/v1/reference/users/threads
But the payload field returns the base64 of the body of the email. When an email is in a thread, it is usually to reply to a previous email. Therefore only the reply part is useful to show. The reply part can be shown by the GUI interface. Is there a way to get only the reply part via the API?
Unfortunately, there's no direct method of obtaining the last reply for each thread.
If you want to retrieve the last reply of the email threads you should first of all retrieve all the messages by using a GET request like this:
GET https://www.googleapis.com/gmail/v1/users/userId/messages
The request response will look something like this:
{
"messages": [
users.messages Resource
],
"nextPageToken": string,
"resultSizeEstimate": unsigned integer
}
Where the users.messages Resource looks something like this:
{
"id": "",
"threadId": ""
}
Having the list of all the users.messages Resources, the ones which contain the same threadId are the emails which in fact contain replies.
So in order to obtain the last reply, you could find which threadIds appear more than once, and then retrieve the last occurrence of it as it is the last reply. Or if you want all the replies (apart from the original email), you can retrieve all the occurrences apart from the first one (which is represented by the original email).
Lastly, to retrieve the message you can use a GET request like this:
GET https://www.googleapis.com/gmail/v1/users/userId/messages/id
Note: The userId is represented by the email address from which you want to retrieve the emails/replies and the id is represented by the id of the message.
Reference
Users.threads: list;
Users.threads: get;
Users.messages: list;
Users.messages: get.

Search emails in Microsoft Exchange/EWS/Office 365

We would like to query our Exchange server for emails based on (for example) the Subject field. Not from a specific address or to a specific address, but rather all emails "that went through the server" and the term X appeared in the subject.
Preferably some standard way like REST / SOAP and so on with HTTPS. Thanks.
You have two options I think, at least with powershell. First and fastest is to do a messagetrace using get-transportservice | get-messagetrackinglog to see what messages have been received and sent.
https://technet.microsoft.com/en-us/library/aa997573(v=exchg.160).aspx
Other would be to search every mailbox for messages conforming to a pre-set filter. You could use get-mailbox | search-mailbox for that.
https://technet.microsoft.com/en-us/library/dd298173(v=exchg.160).aspx
eDiscovery is the most common method you would use to do that https://support.office.com/en-us/article/eDiscovery-in-Office-365-143b3ab8-8cb0-4036-a5fc-6536d837bfce . You can use ediscovery is EWS (SOAP) https://msdn.microsoft.com/en-us/library/office/jj190897(v=exchg.150).aspx the REST API's in Office365 also allow you to search at the folder level https://msdn.microsoft.com/office/office365/APi/mail-rest-operations

Set "reply-to" header field for mailgun

Is it possible to set the "reply-to" header field in a Mailgun list? While conversations are sometimes nice, people are getting annoyed at the volume of mail from one particular list, in which respondents ignore the instruction to send the message to a certain email address and hit reply, resulting in dozens (or more) messages containing things like "Got it!" or "I'm coming!" when only one person needs to see the response.
For this particular list, the ideal situation would be to limit the allowed senders to just a few people, but as none of them use services quite as nice as Gmail or a standalone email client (additional SMTP logins cannot be established), I've not found any way to limit the inanity. Does anyone know how to do this?
I am not sure if you are still looking for the answer, but you can set the Reply-To header using the API.
h:Reply-To
I have been using it with an email hash - each user gets a unique hash in the reply-to field so I know who is replying. Basically the reply-to looks like this:
"h:Reply-To" : "inboundaddress+hash#mydomain.com"
In the routes panel add the following and you can redirect to your email or to an HTTP endpoint:
match_recipient("^inboundaddress\+(.*)#mydomain.com")
Hope that helps.
Justin
You can programmatically add the header "Reply-To" in the data you are sending.
For example, this snippet works well in Python:
import requests
url = 'https://api.mailgun.net/v3/YOUR_ACCOUNT/messages'
auth = ('api', 'YOUR_KEY')
data = {
'from': 'Info <info#email.com>',
'to': ['user1#email.com', 'user2#email.com'],
'subject': 'test email',
'html': '<b>hello!</b> that's all.,
'text': 'plain text here',
'o:tag': ['categoria 1', 'categoria 2']
}
data['h:Reply-To']="My name <my#email.com>" # <------------- HERE!
res = requests.post(url, auth=auth, data=data)
Please check this issue in mailgun-js
https://github.com/bojand/mailgun-js/issues/57
You just need to add 'h:Reply-To' to your email configuration object:
const options = {from, to, subject, text, html};
if(replyToAddress){
options['h:Reply-To'] = replyToAddress;
}
That will add new header to the e-mail :)
I have been looking for the exact same functionality and have not yet found one. I even tried using the Routes but that did nothing more than forward an email before sending it out to everyone else. I opened a ticket with support and received the same reply. There is not a way to set that at this time.

Change the sender for an external email in SO_NEW_DOCUMENT_ATT_SEND_API1 function

I'm using SO_NEW_DOCUMENT_ATT_SEND_API1 function to send an email with an attachment both for a sap user and for an external email. So far, so good. I discovered that the sender of these emails is the sap user that fired the report and the function doesn't have the sender exportation parameter like the old SO_DOCUMENT_SEND_API1 has. The problem is that I need the sender to be an external email. I've been searching and couldn't make this happen. Can anyone help or give me an idea? Thanks
As I have already stated in an answer to another question of yours, stop using the old API and use the new BCS API. The documentation contains an example on how to change the sender address:
DATA: lr_send_request TYPE REF TO cl_bcs,
lr_sender TYPE REF TO cl_cam_address_bcs.
lr_sender = cl_cam_address_bcs=>create_internet_address( 'foo.bar#baz.com' ).
lr_send_request->set_sender( lr_sender ).
Just try to copy the example report BCS_EXAMPLE_1 to your local namespace and exchange the line that sets the sender (line 50 in my release, might be a different one on your system).

How to make an email bot that replies to users not reply to auto-responses and get itself into mail loops

I have a bot that replies to users. But sometimes when my bot sends its reply, the user or their email provider will auto-respond (vacation message, bounce message, error from mailer-daemon, etc). That is then a new message from the user (so my bot thinks) that it in turn replies to. Mail loop!
I'd like my bot to only reply to real emails from real humans. I'm currently filtering out email that admits to being bulk precedence or from a mailing list or has the Auto-Submitted header equal to "auto-replied" or "auto-generated" (see code below). But I imagine there's a more comprehensive or standard way to deal with this. (I'm happy to see solutions in other languages besides Perl.)
NB: Remember to have your own bot declare that it is autoresponding! Include
Auto-Submitted: auto-reply
in the header of your bot's email.
My original code for avoiding mail loops follows. Only reply if realmail returns true.
sub realmail {
my($email) = #_;
$email =~ /\nSubject\:\s*([^\n]*)\n/s;
my $subject = $1;
$email =~ /\nPrecedence\:\s*([^\n]*)\n/s;
my $precedence = $1;
$email =~ /\nAuto-Submitted\:\s*([^\n]*)\n/s;
my $autosub = $1;
return !($precedence =~ /bulk|list|junk/i ||
$autosub =~ /(auto\-replied|auto\-generated)/i ||
$subject =~ /^undelivered mail returned to sender$/i
);
}
(The Subject check is surely unnecessary; I just added these checks one at a time as problems arose and the above now seems to work so I don't want to touch it unless there's something definitively better.)
RFC 3834 provides some guidance for what you should do, but here are some concrete guidelines:
Set your envelope sender to a different email address than your auto-responder so bounces don't feed back into the system.
I always store in a database a key of when an email response was sent from a specific address to another address. Under no circumstance will I ever respond to the same address more than once in a 10 minute period. This alone stopped all loops, but doesn't ensure nice behavior (auto-responses to mailing lists are annoying).
Make sure you add any permutation of header that other people are matching on to stop loops. Here's the list I use:
X-Loop: autoresponder
Auto-Submitted: auto-replied
Precedence: bulk (autoreply)
Here are some header regex's I use to avoid loops and to try to play nice:
/^precedence:\s+(?:bulk|list|junk)/i
/^X-(?:Loop|Mailing-List|BeenThere|Mailman)/i
/^List-/i
/^Auto-Submitted:/i
/^Resent-/i
I also avoid responding if any of these are the envelop senders:
if ($sender eq ""
|| $sender =~ /^(?:request|owner|admin|bounce|bounces)-|-(?:request|owner|admin|bounce|bounces)\#|^(?:mailer-daemon|postmaster|daemon|majordomo|ma
ilman|bounce)\#|(?:listserv|listsrv)/i) {
That really sounds like something that's probably available as a module from CPAN, but I didn't find anything clearly relevant in five minutes of searching. Mail::Lite::Mbox::Processor looks like it might do what you want:
Mail::Lite::Message::Matcher is a
framework for automated mail
processing. For example you have a
mail server and you have a need to
process some types of incoming mail
messages automatically. For example,
you can extract automated
notifications, invoices, alerts etc.
from your mail flow and perform some
tasks based on content of those
messages.
but its docs are sparse enough that it isn't immediately obvious whether it provides those example functions itself or if you have to provide the code to drive them.
In any case, though, if you haven't already checked CPAN, that's where I would start if I wanted to do something like this.
My answer here only deals with bounces which is more straightforward.
Using DSN (Delivery Status Notification) identifier will help you detect a DSN/bounced message. It should go to Return-Path and not Reply-To.
Here's a sample of a typical DSN message. The header information includes the message id, content type has specific values (delivery-status) etc.
Not able to provide you any codes in perl, just my 2 cents of idea.
PS: Do note that not all mail servers or MTA conforms to this, but I guess most do.
There should be a standard way of dealing with this, but the problem is that you'd have to assume that systems that send auto-replies comply to that standard, when most the time, they just don't.
How do you get the address that you reply to? I hope you aren't using the From: header. Check the Reply-to: header first and if that doesn't exist, use the Return-path:.
But whatever you do, you will simply have to keep a log of what you sent to whom and throttle your bot to some sensible value of messages per time.