Get Message ID in response of send mail - SendGrid API v3 - php

I am getting this response when I submit an email, as I am working on the API of SendGrid I need to grab the stats of each mail i sent.. for that purpose I want the Message-ID in response so I could save that in db.. I have looked over the docs but unable to make any progress.. Thanks in Advance
But i want to get email activity by passing message ID
Note: Currently mail response give "X-Message-ID" but i want Message ID
https://sendgrid.api-docs.io/v3.0/email-activity/filter-messages-by-message-id
Thanks...

The X- prefix in a header means that it is a custom header and not part of the standard. This has become less favoured over time, but it is still found in use across the internet. X-Message-Id is what you're looking for.

Related

Laravel 5.2 get response from Mail (MailGun, Mandrill, Sendgrid or whatever)

How can I get the Laravel Mail class response?
I am working with Sendgrid and I know that when I "ask" it to send an email it gives me back a MSGID and I would like to get it to keep in my database but the Laravel Mail class does not give any response!
Somebody knows how to do that?
---------------- EDITING FROM HERE
Actually I am gonna improve my question =)
I need to work with webhooks to know when the e-mail is delivered, opened and clicked!
How can I link the webhook received from Sendgrid with the emails on my "sent_mails" database table?
By the Sendgrid Panel I find a MSGID that is equals for every action from a specific e-mail but I don't have that ID on my base to link it!
Good news!
For SendGrid at least just found a good solution!
We can add custom fields when send an email and those fields will be on the webhook sent from SenGrid to you application!
So you can add a custom field with the ID of your record and it will be on the post data sent back to you by webhook =)
https://sendgrid.com/docs/Integrate/Frameworks/laravel.html
Easy!! Hope it helps someone else as well!

Amazon SES bounce/complaint handling

Currently we are using Mandrill to send our emails, when ever Mandrill detects a bounce we get the original headers along with the bounce or a subaccount where the email was send from.
In Amazon SES we are getting the notifications through SNS thats no problem but besides the email from the user we get no original information back. So we have no idea what email campaign the user bounced on etc.
Anybody that knows how to handle this?
every SNS message contain a "mail" part with the messageId see. If you are sending a mail you receive as the only response the messageId see.
so I store all the messageId together with information I later maybe need if that mail bounces or gets complaints and if I receive a bounce I can query all the information with the given messageId.
You can use the regular expression to get messageId
In python i use like this
message_id = re.findall(r"(\w+(?:-\w+)+)#email.amazonses.com", json.dumps(event))[0]
Similar thing you can try in php

Receiving SMS and storing it in database using Twilio

i am using Twilio API to send and receive sms from the customers.
Every time i send the sms to my customers, i store the feilds like to, body in to my database.
I have implemented the API for send message that works fine and am simply saving the fields in to my database.
My Problem
When i receive SMS from my customers to my twilio number. i want to get the fields like from number and the body and save to my databse.
i looked that the documentation here
https://www.twilio.com/docs/api/twiml
https://www.twilio.com/blog/2012/04/get-started-with-twilio-sms-receiving-incoming-sms-quickstart.html
But this only shows how to send a response to customer when a message is received.
I want to save the received sms in to my database.
Can someone help me top get the from number and the message body when a SMS is received. tnx..
Twilio evangelist here.
Twilio passes parameters in its HTTP request as form-encoded values, so you just need to use the REQUEST object to grab them:
$from = $_REQUEST['From']
The SMS Quickstart for PHP has a more detailed example.
Hope hat helps.
The documentation for Twilio SMS responses is here:
https://www.twilio.com/docs/api/twiml/sms/twilio_request
Here is a relevant quote:
When Twilio receives a message for one of your Twilio numbers it makes
a synchronous HTTP request to the message URL configured for that
number, and expects to receive TwiML in response. Twilio sends the
following parameters with its request as POST parameters or URL query
parameters, depending on which HTTP method you've configured.
You should simply have the data fields inside of PHP's $_REQUEST[] variable.
$_REQUEST['MessageSid'] - A 34 character unique identifier for the message. May be used to later retrieve this message from the REST API.
$_REQUEST['SmsSid'] - Same value as MessageSid. Deprecated and included for backward compatibility.
$_REQUEST['AccountSid'] - The 34 character id of the Account this message is associated with.
$_REQUEST['From'] - The phone number that sent this message.
$_REQUEST['To'] - The phone number of the recipient.
$_REQUEST['Body'] - The text body of the message. Up to 1600 characters long.
$_REQUEST['NumMedia'] - The number of media items associated with your message
Here is an example query you might use with a MySQL database. You should also be sending back a proper TWIXML response to Twilio and scrub the received data before running a query like this.
$sql = "INSERT INTO messages (sid, from, body)
VALUES (
'".$_REQUEST['MessageSid']."',
'".$_REQUEST['From']."',
'".$_REQUEST['Body']."'
)";

twilio sms api - is my sms delivered or NOT-delivered to end user?

I use twilio API to send SMS from my php application. When the 'to' number is malformed (invalid area code, invalid digits number etc) twilio works fine, giving me an exception.
My problem is when I try to send to a number that is in good format, however it doesn't exist. It show it as 'sent' and no exception is given. I also tried the callback option:
array('StatusCallback' => 'http://uncurler.heroku.com/v1/<some code >').
Even when i view the report here it shows as 'sent'.
Is there a way to actually know if the message was delivered? Or more importantly if it was NOT delivered? If not, is it possible from some other API?
Twilio evangelist here.
So currently the Status value does not reflect anything beyond our ability to deliver the message to the carrier. It does not reflect any information about whether or not the carrier was able to deliver the message or not.
If the carrier accepts the message from us, we mark the message as Sent.
Hope that helps.

How to manage answers directly on email notifications

I would like to know what's the best way to manage answers to email notifications.
eg. The user receive an email notification, and instead of having to click on a link to go on the website and answer it he could directly reply to the email.
There's no best way. Depending on what you want to do with the responses, you could as well handle them with thunderbirds message filters ;) .
Put a unique identifier into the subject or the body of the notification that you're sending so that you can identify & classify the email correctly when a user replies by email.
If you want to stick with php: pick up the php pop3 client class from: http://www.phpclasses.org/browse/package/2.html or find a client elsewhere and then just parse your message responses and classify / handle them however you want to.
Use the Message-ID header field to uniquely identify each message. If there is a reply on that message, the client should put that message ID in the In-Reply-To header field in the reply message. See RFC 2822 for further details.
Stick an id and authentication token in the subject line.
Pipe it into a script that can process it with Procmail
As a learning exercise you could read the php code and Documentation to the drupal module http://drupal.org/project/mailhandler mail handler. This accepts emails and looks for script like instructions.
The answer above about checking the message id is also very valid.

Categories