How can i resend SMS with Twilio api? - sms

I am trying use Twilio api to send SMS to my customers. When i use trial account, i'm using this code:
<?php
require('Services/Twilio.php');
$account_sid = '{my_sid}';
$auth_token = '{my_token}';
$client = new Services_Twilio($account_sid, $auth_token);
$callback=$client->account->messages->create(array(
'To' => "+84974366xxx",
'From' => "+14845280xxx",
'Body' => "hello world",
));
print_r($callback);
?>
The sms i received had "Send from twilio trial account" before "hello world". Now i upgraded my account and test this code again. It's still respone successfully, but my phone number isn't receive SMS. Now how can i check status of $callback and resend sms?

You can make use of the status call back parameter.
This allows you to configure a url that Twilio will call, in this you will receive various details about the action that you configured it with. For sms, you can expect status values like failed, sent, delivered that is just to mention a few. you can then use these values to determine if further action is required, such as resend the message and so on.
for more details I suggest looking at the Twilio message api here
https://www.twilio.com/docs/api/rest/sending-messages#post-parameters-optional
I hope this helps

Related

Use TwiMl templates for sending outbound sms

I am new to Twilio. We have a requirement in the project as follow -
Send an outbound SMS to a given number. The message body is static text and should be defined using a template on Twilio(TwiML), so that client can change the message body anytime without making any changes in the backend application.
I have gone through the Twilio documentation to understand how to use TwiML, but couldn't find any document or article which explains how to use TwiML for sending an outbound SMS. Currently I am using following code to send a SMS and the message is configured in the Spring Boot application.properties file.
Message message = Message.creator(new PhoneNumber(phoneNumber),
new PhoneNumber(fromPhoneNumber),
messageBody).setStatusCallback(URI.create(callBackUrl)).create();
Does anyone know how to use TwiML template to send an outbound SMS. Can someone help me to solve this problem. Thank you.
What is Twiml?
Twiml is instructions for Twilio, how to respond to an incoming phone call,SMS, etc...
What is Twiml
It is not for outbound actions.
To initiate an SMS , you should use the Twilio api which is what you are doing when you use the sdk such as Message.creator

How do I retrieve the sender number when using Twilio's messaging services with Copilot enabled?

I have a Twilio messaging service with Copilot and the sticky sender feature enabled.
I would like to view the phone number that Copilot assigns to my recipients when I send them a message.
With the Ruby client, I get a MessageContext object when I send a message, but it only has the
messaging service SID - the from method returns nil.
Currently, this is how I'm sending messages:
def send(from, to, message)
client = Twilio::REST::Client.new(ACCOUNT_SID, AUTH_TOKEN)
client.api.account.messages.create(
body: message,
messaging_service_sid: from,
to: to,
status_callback: BASE_URL + '/sms_status/status',
)
end
Twilio developer evangelist here.
I'm not sure, but you might not have the phone number at the time you make the API request using a messaging service. This request really just queues up the message to be sent.
I would check the message object once it has been sent. You have a status callback URL setup, so you should be able to either inspect the parameters sent to that URL or look up the message from the API using its SID and then get the number that was used.

Cannot send emails to yahoo using mailkit

I am creating a system that sends emails (pricing, orders, invoices, etc) to out customers. But due to the number of emails that ends up being, we hit limits when trying to send through gmail or any other mail client. And since these are all customer specific emails using a bulk sending client is not ideal.
So I have created a system using mailkit and others to send our emails from our own servers without needing to set up a relay or email server for sending. This works great with everyone (Gmail, outlook, etc) except for yahoo. For some reason when I connect and mailkit tries to switch to STL (via startstl) yahoo sends garbage and mail kit fails.
I have enabled all ssl and tsl protocols. And I have ServerCertificateValidationCallback always to return true. In fact ServerCertificateValidationCallback doesn't even get called.
The errors that are thrown start with:
A call to SSPI failed, see inner exception
then
The message received was unexpected or badly formatted.
If I try to connect to any of the other SMTP ports 465 or 587 the system just hangs.
This all happens when connecting, before the email is sent. So it cannot be a DKIM issue. And the SPF record is set up correctly. We don't have the reverse dns setup because we plan on sending from multiple servers with different IPs.
I don't know why yahoo is being so difficult.
Tried talking with MailKit, tries allowing all TLS and SSL connections. Tried finding any YAHOO support.
using (var client = new SmtpClient())
{
client.LocalDomain = "MyDomain";
// right now we don't care about all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (s, c, h, e) => {
return true;
};
client.SslProtocols = System.Security.Authentication.SslProtocols.Tls11 |
System.Security.Authentication.SslProtocols.Tls12 |
System.Security.Authentication.SslProtocols.Tls |
System.Security.Authentication.SslProtocols.Ssl3 |
System.Security.Authentication.SslProtocols.Ssl2;
client.CheckCertificateRevocation = false;
client.Connect("mta6.am0.yahoodns.net", 25, false); //<--- fails here
client.Send("test", fromMailBoxAddress, recipientsEmailBoxAddresses);
client.Disconnect(true);
}
To answer your question, I might have an idea why Yahoo is being so difficult - it's possibly your message construction. Verify your MimeMessage has the same exact email address for your From and Sender addresses. Ensure your ReplyTo only contains the Sender email address. I had both the sender and recipient email addresses in the ReplyTo and Yahoo did NOT like that. And, of course, you are using a Yahoo App password for authentication. Once I made these two changes, Yahoo sent the email successfully.
Settings
client.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
client.DeliveryStatusNotificationType = mail.DeliveryStatusNotificationType.Full;
await client.ConnectAsync("smtp.mail.yahoo.com", 587, SecureSocketOptions.StartTls);
await client.AuthenticateAsync(yourEmailAddress#yahoo.com, yourYahooAppPassword);
await client.SendAsync(Message);
await client.DisconnectAsync(true);
Research
Bad message construction breaks one of Yahoo's many policies. This was ONLY happening with SMTP via Yahoo. SMTP via Gmail and Outlook work fine. I kept comparing a simple MailMessage with MimeMessage message construction. MailMessage sent, MimeMessage failed, I kept getting a 550 request failed; mailbox unavailable response from Yahoo every time with my MimeMessage. I verified by using ProtocolLogger. My From was empty and that is one issue, and, I had the recipient in my ReplyTo. If I merely added the sender to the ReplyTo, it still throws that same 550 error. I had to ensure the sender was the only email in the ReplyTo.
Hope this helps.
Use client.Connect("mta6.am0.yahoodns.net", 25, SecureSocketOptions.None); if you want to disable STARTTLS or use client.Connect("smtp.mail.yahoo.com", 587, SecureSocketOptions.Auto); which works fine.
Not sure where you are getting "mta6.am0.yahoodns.net" from, but I can't even make a normal socket connection to that address.

Codeigniter - Mail sent using MAIL protocol but not received - debugger shows no error

Array ( [useragent] => Stock Manager Advance [protocol] => mail [mailtype] => html [crlf] => [newline] => )
This is the $config parameters passing to the Email library to Initialize.
While sending email it returns true but mail not received. I've tried SMTP and Send Mail too but its not working anymore.
When I've tried to debug email for any errors it was just print as <pre></pre>.
Is there any possibilities to find the error? or anything like server error.
Need solution. Thanks in advance.

Parse on Buddy.com, push notifications sent via API not delivered

I've almost successfully migrated an existing app from Parse.com to Buddy.com for sending and receiving push notifications.
Registering, acquiring the deviceToken, and subscribing to channels works. I can see the installation details in the data Browser and also sending push notifications directly from the Dashboard works. Notifications are received almost immediately in the app.
Now I have changed my server application (using the Parse PHP-SDK 1.2.1) to use the Buddy API endpoint and configured it to use the masterkey for authentication. Although sending a push notification via the API doesn't give an error and is even returning "result => 1", notifications are never received in the application. I can't find a server log like on the original Parse Dashboard at Buddy, so I can't verify if the messages I sent are really queued and picked up for delivery.
I'm a missing something essential?
Solved it! Seems that the Parse.com api accepted push data payload in JSON encoded format. But for the Buddy.com platform, data should be passed as plain array.
My payload as I pull it from our notification queue:
$data = '{"alert":"Test bericht"}';
Although returning result => true, this won't work:
ParsePush::send(array(
"channels" => ['user_1234'],
"data" => $data
), true);
This works as expected:
ParsePush::send(array(
"channels" => ['user_1234'],
"data" => json_decode($data, true)
), true);

Resources