I have sent my mail through java mail and registered my email on Amazon to get the response notifications (Bounce, Delivered) etc.
How can i succesfully match these two to say when i have sent the mail, the mail i sent has the following incomming response.
Note: Everything is setup (Webhooks to get the response from AWS SNS)
I tried matching it by the messageId, but it seems aws adds a different messsageId than the java mail one. Example
MimeMessage msg = new MimeMessage(session);
msg.getMessageID(); // returns "<1619401941.3.1560500581268#Tinus-NB>"
And the from the AWS SNS response
"MessageId" : "7cd42bc4-e5c2-576b-a567-7eb9baa51cad" // directly
"Message" : "{\"notificationType\":\"Delivery\",\"mail\":{\"timestamp\":\"2019-06-14T08:38:55.113Z\",\"messageId\":\"0102016b5523c189-55acd572-ba3f-4750-aaae-b7019080f1ae-000000\",\"delivery\":{\"timestamp\":\"2019-06-14T08:39:03.043Z\",\"processingTimeMillis\":7930,\"smtpResponse\":\"250 2.0.0 OK 1560501543 f15si1572805ede.113 - gsmtp\"}}" // this is in the Message object in the JSON
Just to be clear, I want to match these two, to know what i sent and what the response was.
I am using Java Mail and not the AWS SDK lib
SES overwrites MessageID whatever you set because it also needs to know which email is it. In your case, when sending emails from Javamail,in the last section of your code, you can print the 250 response code+ message ID from SES and match it with the message ID you received from SNS.
When SES accepts an email in SMTP conversation, it gives 250 ok+ message ID and the same message ID can be seen in SNS notification.
Found it, i just had to include the original headers
Related
Need to track the emails so before sending emails I need to get the message id of the email message.
All you need is to save the EmailMessage first before you send it.
EmailMessage emailMessage = new EmailMessage(service);
emailMessage.save();
EWS saves the email message and assigns an Internet message identifier to it. But on your local emailMessage this property still isn't set. Trying to access it by
emailMessage.getInternetMessageId();
will result in a ServiceObjectPropertyException. You need to get the remote and updated version of the email message:
emailMessage = EmailMessage.bind(service, emailMessage.getId());
Now you can read the Internet message identifier property. Set other properties as needed and then send the message.
I am creating a program that asks the user something like "How are you doing today":
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(new PhoneNumber("+000000"), // To
// number
new PhoneNumber("0000000"), // From number
"How are you doing today?" // SMS body
).create();
System.out.println(message.getSid());
And then then the program will listen for whatever response the user texts back from their phone.
Now, Twilio says this about receiving SMS:
You can associate that phone number with an SMS URL. When someone sends a text message to that phone number, Twilio makes an HTTP request to your URL with the body of the message and the sender's phone number. You can then respond to the SMS by returning a reply message in the HTTP response to Twilio.
Now, I understand that when the user texts back, Twilio makes an HTTP request to my program, like so:
However, in the tutorial, they create an HTTP tunnel using ngrok to allow the HTTP request to go through. My application is supposed to be able to run in anyone's computer without prior configuration. How would you recommend I achieve this?
I'm afraid that without exposing your application to the Net you won't be able to use that particular API.
What you can try to do instead is polling / fetching:
When you send an SMS or MMS message via the REST API, using the
<Message> verb in TwiML, or someone sends a message to one of your
Twilio numbers Twilio creates a Message instance resource. The
Messages list resource represents the set of messages sent from and
received by an account.
Retrieving sent and received messages from history can be achieved by
querying the Messages list resource.
A short example to start with is available here.
I'm using Javamail to connect to an AWS email service; I've tested that I can receive emails using this code, but I would also like to get a response with data about the sent email, such as the Message ID, which AWS uses to uniquely identify a message.
I'm using MimeMessage to create an email and I am sending it with this code within a try catch block:
transport.sendMessage(message, message.getAllRecipients)
This code just fires off an email to the AWS server and I can't get any metadata back. Is there a way to listen for a response to see if the message was successful so I can retrieve the Message ID?
If the sendMessage method returns, the server accepted the message. Note that that doesn't necessarily mean it will be delivered to the recipient, however. But at that point you can use the getMessageID method to retrieve the message ID.
If the send method throws an exception, the server refused to accept the message for some reason and it won't be sent.
add properties mail.smtp.reportsuccess and mail.smtp.sendpartial to you java Mail Properties, you will get SMTPAddressSucceededException if send email success or SMTPAddressFailedException in fail.
javamail doc
Messages are not delivered to numbers but Twilio is charging me and giving me status sent only with my code.
private val client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
def sendSMS(smsTo: String) = {
val params = Map("To" -> smsTo, "From" -> twilioNumber, "Body" -> "status?")
val messageFactory = client.getAccount.getSmsFactory
messageFactory.create(params)
}
But when I am using API Explorer its giving status delivered.
Is it my code's fault or Twilio?
I want my SMS delivered to users.
Twilio Evangelist here here.
When you send the SMS message using the REST API (the Java/Scala helper library here) you are getting the status sent because Twilio has sent the message to the carrier. The carrier will typically update Twilio to say the message was delivered.
There should be nothing wrong with your code at all. What you can do is capture the return value from:
messageFactory.create(params)
Which will contain a message ID (messageSID below). You can then fetch this message from the server to get an update on its status with something like:
var params = Map("SID" -> messageSID)
client.getAccount.getSmsMessage(params)
The full list of status are here. But it looks like everything you have should be spot on. Hope this helps.
I am using the Twilio java wrapper provided on the website and started making some tests. I am able to send text messages that are successfully received. However, I would like to make sure that the messages have been sent successfully and that no problem has been encountered by Twilio (bad phone number or whatever reason).
I understand that when you make a REST request to Twilio to send a SMS, Twilio responds with the Status. How could I get this response?
Here is the explanation page I found: http://www.twilio.com/docs/howto/sms-notifications-and-alerts
If you specify a StatusCallback URL when you make the request to send an SMS, we will make a request to the callback URL you provided after the message has finished processing, with the parameters either SmsStatus=sent or SmsStatus=failed. You can use this information to do more processing on the SMS message. There's more information here: http://www.twilio.com/docs/api/rest/sending-sms#post-parameters-optional
Alternately, if you hang on to the SMS Message Sid, you should be able to query the API for the message and get the status in the response. So if the sid is SM123, making a GET request to https://api.twilio.com/2010-04-01/Accounts/AC123/SMS/Messages/SM123.json should return a object with the status of the SMS Message.
I recall that the response comes to your url and can be matched up by an ID. In the REST post to SMSMessages you can specify a statuscallback url where Twilio will post a status message to your url.
When you receive that post to your site, you can record it or take any other action you need, such as retrying or using another mode of communication.
In 2020, with the Java SDK, you can now create a MessageFetcher with that SID and then call fetch to ask for the Message instance until its getStatus returns "delivered", "undelivered", or "failed".