Error in sending 2nd text from "twilio rest api" - c#

I am sending messages form my application. But, when sending 2nd text from application, then the message is not sent. I don't know why?
here is the code
for (int i = 0; i <= numbr.Length; i++)
{
var statusurl = "";
var nums = numbr[i];
var delivery = twilioRestClient.SendSmsMessage("+13082242885", nums, msg);
var sq = delivery.Sid;
statusurl = delivery.Uri.ToString();
//store statusurl array to db
}
Help me in getting out of the problem. First message is sent easily and received in very short time.
Answer
the api is not sending 2nd text because i am using twilio Trial account which only allow me to send message to my own verified number
https://www.twilio.com/docs/errors/21608

Twilio Trial accounts send sms to only verified numbers log into your account in twilio portal and verify that number to which you are sending sms. Twilio will call on that number and will ask you type a pin code.
Hope that helps

Twilio evangelist here.
Couple of suggestions.
Check to see if Twilio is returning an error by checking to see if deilvery.RestException is null.
Check the Twilio log in your dashboard to see if Twilio says its sending the second message.
Hope that helps.

Related

How to send whatsApp message to any number by using twilio using c#

I am new to Twilio
below is my code to send whatsapp message using C#
static void Main(string[] args)
{
// Find your Account Sid and Token at twilio.com/console
TwilioClient.Init(Model.AccountSid, Model.AuthToken);
var message = MessageResource.Create(
//whatsapp message
to: new PhoneNumber(Model.To), from: new PhoneNumber(Model.From),
body: "Ahoy from Twilio!!!!!"
);
Console.WriteLine("Message SID: " + message.Sid);
}
Model.To have my whatsapp number which I have used while registering with twilio.
Model.From have Twilio's WhatsApp number
if I run this console application then I get message on my whatsapp number
but when I try to send message to my friend's WhatsApp number by assigning that number to Model.To,
I am not getting message on that number
How can I achieve it?
is there any other way to achieve it without twilio?
Thanks in advance.
Did you check the Twilio Debugger for errors. If you are sending the first message from Twilio out to the WhatsApp user, you must initially use a Template, as detailed here.
If you are using the Trial account then
1)first verify that number from here https://www.twilio.com/console/phone-numbers/verified
2)after verifying the number ,send whatsapp message from verified number to the twilio's whatsapp number using your sandbox code (code will be like e.g join XYZ-PQR)
3)after sending the whatsapp message that number will join your sandbox and you will be able to send message on that number

Fetched Emails not ordered when I use pop3

First I were Fetching emails by POP3 using this library OpenPop.Pop3 and it was working ok and it was returns emails ordered from last email to first email
but when I change the library to mailkit library the returned messages not ordered and couldn't know based on what mailkit order fetched emails
that's my code after I change to mailkit library
using (Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(hostname, port, useSsl);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate((username), password);
int messageCount = client.Count;
// We want to download all messages
List<MimeMessage> allMessages = new List<MimeMessage>(messageCount);
for (int i = messageCount-1; i > 0; i--)
{
var msg = client.GetMessage(i);
allMessages.Add(msg);
}
}
by this way allmessages variable should contains emails ordered from last email to first email but that's not happened emails not ordered at all
although I were using the same authenticated email before with OpenPop.Pop3 and fetched emails were ordered
I don't know why they wouldn't be ordered for you since MailKit is not doing any kind of sorting.
That said, MailKit uses 0-based indexes while I suppose OpenPOP.NET must have used 1-based indexes, so your loop should make the following change:
for (int i = messageCount-1; i >= 0; i--)
{
var msg = client.GetMessage(i);
allMessages.Add(msg);
}
Perhaps this will produce the expected results?
Update: It turns out that MailKit was correctly downloading the messages in reverse order just as his code was trying to do (as mentioned in his follow-up question). The problem this user was facing is that his GMail account settings were only providing MailKit's Pop3Client with a subset of his total Inbox as is explained in Google's FAQ in the section titled "Emails aren't downloading correctly", where it states:
After you set up POP in your Gmail settings, your emails become available
in batches. It might take a while to see all your emails.
Note: Gmail downloads a copy of every email you send or receive, except
for emails in Chats, Spam, and Trash. To avoid duplicates, Gmail doesn't
download emails sent within your mail client, but you can still see them
if you log in to Gmail.
If you continue to have problems downloading emails, try using recent
mode:
In your email client's POP settings page, find the "Email address" or
"User name" field.
Add recent: in front of your email address. For example,
recent:example#gmail.com.
If that doesn't fix the problem, try deleting your Gmail address from your email client, then re-adding it.

How to pick up where it left during the download of SMS message logs from Twilio

I know that to download SMS messages we do this:
// Find your Account Sid and Auth Token at twilio.com/console
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "your_auth_token";
TwilioClient.Init(accountSid, authToken);
var messages = MessageResource.Read();
foreach (var message in messages)
{
Console.WriteLine(message.Body);
}
I am downloading a good amount of messages. This operation might take up to 12 hours. Now if anything happened within the foreach loop, I have to restart the process.
I am wondering what I can do so that the program can resume the download process should any error happened.
Update a variable within the loop to save the DateSent value of the latest message you have processed.
If an error is thrown you can supply the DateSent as a list filter in your next request to the Twilio API and it will only return message on/before/after that date.
Only show messages sent on this date (in GMT format), given as
YYYY-MM-DD. Example: DateSent=2009-07-06. You can also specify
inequality, such as DateSent<=YYYY-MM-DD for messages that were sent
on or before midnight on a date, and DateSent>=YYYY-MM-DD for messages
sent on or after midnight on a date.
I think the API also returns paging information, so you could do something similar using that.
Either way you would probably still get a few duplicates around the point of failure so you would need to be saving each message Sid somewhere so you can filter those out too.

No verification code while registering number via message using twilio trial

Hi I am on trial with twilio.
I have seen this link:
https://www.twilio.com/help/faq/twilio-basics/how-does-twilios-free-trial-work
It says "You must verify a phone number before you can send SMS messages to it from your trial phone number."
And also restricts on the outgoing text
But what if I just want to verfiy the number, using:
var twilio = new TwilioRestClient(
Keys.TwilioSid,
Keys.TwilioToken
);
var result = twilio.SendMessage(
Keys.FromPhone,
message.Destination, message.Body);
// Status is one of Queued, Sending, Sent, Failed or null if the number is not valid
Trace.TraceInformation(result.Status);
// Plug in your SMS service here to send a text message.
return Task.FromResult(0);
I get null when I try to verify the number that are not in the dashboard(web twilio) whereas those with verified from dashboard gets the verification from above code.
Is it intended? I think we need to be able to register at least from web interface?
Error: Account not authorized to call . Perhaps you need to enable some international permissions: twilio.com/user/account/settings/international For Message The number XX is unverified. Trial accounts cannot send messages to unverified numbers; verify xxx at twilio.com/user/account/phone-numbers/verified, or purchase a Twilio number to send messages to unverified numbers
I don't think you can verify a number in the way that you are attempting to do it. Verifying a number adds it to your outgoing numbers. you can look at this page, which provides the full details. https://www.twilio.com/docs/api/rest/outgoing-caller-ids#list-post-example-1
A snippet from the page using the C# Api,
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "{{ sid }}";
string AuthToken = "{{ auth_token }}";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var callerId = twilio.AddOutgoingCallerId("+14158675309", "My Home Phone Number", null, null);
Console.WriteLine(callerId.ValidationCode);
The first argument is the number you would like to verify, and the second argument is simply a friendly name for the number. The above process will initiate a call to the number and ask you to provide the validation code. You will then use the value that is printed to the console and enter that during the validation process, provided that all goes well, once the above process is complete, the number would be verified and you will be able to send an Sms to that number.
Twilio evangelist here.
A trial account has a number of restrictions placed on it, including you can only send SMS messages to verified phone numbers. A verified phone number will show up in your Twilio dashboard under Numbers > Verified Caller IDs:
https://www.twilio.com/user/account/phone-numbers/verified
To verify a number using the .NET helper library, call the AddOutgoingCallerId method like Lewis showed.
Calling this method returns to you a six digit verification code. Twilio will then call the number that you want to verify and ask the person who answers to enter that 6 digit code. If the code entered matches, Twilio adds that phone number as a Verified Caller ID and you an send text messages to it.
Note that while using a Trial account, messages will also be prefixed with the message "Sent from a Twilio Trial account".
If the request to the Twilio REST API made by the AddOutgoingCallerId method fails (wrong credentials, invalid method parameters, etc), you determine this by checking the RestException property:
var result = twilio.AddOutgoingCallerId("+15555555555","Verified Number",null,null);
if (result.RestException!=null) {
Debug.Writeline(result.RestException.Message);
}
Hope that helps.

TWILIO cannot send sms from C# console app

I'm having a problem to use TWILIO to send sms from C# console app. Initially I faced an error mentioning "Method not found: 'Void RestSharp.RestClient.set_BaseUrl(System.String)'." After applying solution given in another post the application now runs. However it does not send any sms. After looking at response in another post, I tried using the RestException property and found the following message as exception message "Permission to send an SMS has not been enabled for the region indicated by the 'To' number: +880161xxxxxxx.". So does it mean that Twilio based application cannot work for Bangladesh (+880 country code)? Do you have any plan to update it? However I would like to add mentioning that from the Twilio website I could manage to validate the number(+880161xxxxxxx) by sending verification sms from twilio website.
I tried the following code
using Twilio;
namespace SMSTestApp1
{
class Program
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "xxx";
string AuthToken = "yyy";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage("+1205490xxxx", "+8801615xxxxxx", "Test Message", new string[] { }, String.Empty);
Console.WriteLine(message.Sid);
if (message.RestException != null)
{
Console.WriteLine(message.RestException.Message);
}
Console.WriteLine("Finish");
Console.ReadKey();
}
}
}
I think you need to log into your Twilio portal, click on the top right where your account name is, and select account from that drop down menu. Once that loads, you can select geographic permissions. You will find a list and you will need to enable the country that you are attempting to send too.

Categories