I am trying to calculate the time taken to send email message and time taken to receive email message. i am using EWS in my program , I set streaming notification to receive call back when a new mail reaches reciptent mailbox .
once received notification i bind the Itemevent with ews service , i checked the item properties DateTimeCreated, DateTimeSent, DateTimeReceived.All these properties are of DateTime object.
I checked DateTimeSent milisecond is always 0, whereas DateTimeCreated, DateTimeReceived has millisecond value.
I couldnot figure out why DateTimeSent millisecond is always 0 everytime. if i want to claulate time taken from send to receive what should i do.
DateTimeReceived - Datetimesent is the actual time taken to send and receive the message?
or what is the correct way to calculate time taken to send and receive the message?
set DateTimePrecision as Milliseconds
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials(username, password);
service.Url = new Uri(ConfigSettings.EmailConnectionUrl);
service.DateTimePrecision = DateTimePrecision.Milliseconds;
how about actually measuring the Timespan? so for example showing total milliseconds but you could change that to suit
var result=((TimeSpan)(DateTimeReceived - DateTimeSent )).TotalMilliseconds.ToString("#,##0.00") + "ms";
In the EWS Managed API the ExchangeService class has a precision property that you need to set before you make any calls see https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.exchangeservice.datetimeprecision(v=exchg.80).aspx
Related
I'm developing a graphic user interface where the user can send a message to mutuple user using Twilio API in c#
I'm trying to bind a list view to the status of each number being sent and I also want to know the status of the message every time the user click on refresh list view
public void sendSMS(string ssid, string token , string fromNumber, List<string>TOnumbersList ,string msgBody )
{
TwilioClient.Init(ssid, token);
foreach (var toNumber in TOnumbersList)
{
var message = MessageResource.Create(
to: new PhoneNumber(toNumber),
from: new PhoneNumber(fromNumber),
body: msgBody,
provideFeedback: true,
statusCallback: new Uri("http://requestb.in/1jnk4451"));
ListViewItem items = new ListViewItem(message.To);//This show the number being sent to ( delivered number)
items.SubItems.Add(message.Status.ToString()); //Refresh the status WHERE number = message.To
items.SubItems.Add(message.ErrorCode.ToString());//Show error code in case
items.SubItems.Add(message.ErrorMessage); // In case error message show them
listView1.Items.AddRange(new ListViewItem[] { items });
}
}
Twilio API is doing the perfect job updating the status so everytime I go click the link I can see the status. as explained in this documentation Track Delivery Status of Messages in C#
But is It possible to bind a list view so it can be updated everytime the user click on refresh list view ?
Or what is the best way to dynamically show the message status from the URI http://requestb.in/1jnk4451? Maybe embedding a webpage would be better ?
Thank you
Twilio developer evangelist here.
Rather than using the RequestBin URL, if you provide a URL to your own application then you can write an endpoint that receives the status updates of the messages. That way you can store the status yourself and update the list view without having to loop through all the messages.
[Edit] In more detail:
When you send an SMS message with Twilio using the REST API you can set a statusCallback URL to receive updates about the message as it processes through from Twilio to the network and the device.
Twilio will make HTTP requests to this URL as the message goes through each state, the possible states being queued, failed, sent, delivered, or undelivered. Twilio sends a number of parameters as part of this request, some are general ones about the message and some are about the actual status.
To receive these requests you need to set up a web server. I'm not a C# developer I'm afraid, however we have a guide on how to set up a C# and ASP.NET MVC environment that can receive webhooks that should be able to help you there.
Let me know if this helps a bit more!
I am trying to discover if there is a way to determine the internet message ID after sending an email using the EWS Managed API. I understand you can go in there and get the results from the sent box, but the server that is sending these emails is sending multiple emails at a time from different services.
No you can't, basically because EWS sends message Asynchronously the Id isn't available see https://social.msdn.microsoft.com/Forums/azure/en-US/dd034b8c-ffa1-4ae0-9025-45fcf520c9e5/updateitem-does-not-return-itemid?forum=exchangesvrdevelopment
As a work around you might want to consider setting the Internet messageId on the Message before you send it. As long as it valid and unique it should work okay eg
ExtendedPropertyDefinition PidTagInternetMessageId = new ExtendedPropertyDefinition(4149, MapiPropertyType.String);
EmailMessage ema = new EmailMessage(service);
ema.Subject ="test from ews";
ema.Body = new MessageBody("test<br>Rgds<>");
ema.ToRecipients.Add("gscales#domain.com");
ema.SetExtendedProperty(PidTagInternetMessageId,("<" +Guid.NewGuid().ToString() + "#domain.com>"));
ema.SendAndSaveCopy();
Also if you save the message first as a draft before sending it the server will assign the MessageId property which which should then be able to read back using Load.
Cheers
Glen
I am using EWS api for email operations.
When initially user sets up his account, i just need to collect latest syncstate of his account. My CRON job checks for latest changes from then onwards at regular intervals.
Here is the code
var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url = new Uri("https://" + data.ServerAddress + "/ews/Exchange.asmx");
service.Credentials = new NetworkCredential(data.EMail, data.Password);
ServicePointManager.ServerCertificateValidationCallback = (xyzxyz, certificate, chain, sslPolicyErrors) => true;
ChangeCollection<ItemChange> icc = service.SyncFolderItems(new FolderId(WellKnownFolderName.Inbox),
PropertySet.FirstClassProperties,
null,
512,
SyncFolderItemsScope.NormalItems,
null );
return icc.SyncState;
Issue lies in collecting SyncState when user initially sets up his account.
Assume user has 600 email in Inbox. When I request for syncstate with above code, I get syncstate which is valid for first 512 emails. I will have to make one more call to get next syncstate which is valid and final. This will increase waiting time for the user to setup his account. If user has 10000 mails in Inbox, it would be required to make 20 calls to EWS to get final SyncState.
How to get final or latest SyncState with a single call to EWS?
You can't get the latest sync state in a single call, see EWS. How to get latest SyncState without initial synchronization?. Note that starting with Exchange 2010 SP2, EWS returns items from newest to oldest, so the user will get their newest items first - they won't have to wait all 20 calls.
I'm using SMPP client with C# in Vs 2010 to send SMS to SMSC. I just can't figure out how to get the delivery report for the sent messages. I used QuerySM to get the status of the message, but it's returning OK Status even if I send an SMS to the number that is not in use.
Here is my code for getting Delivery Report:
QuerySm deliver = new QuerySm(_MessageID, SrcTon, SrcNpi, SrcAddr);
client.Query(deliver);
It is possible that the SMSC you're using doesn't support query_sm, in this case they may have implemented a placeholder query_sm_resp PDU with a OK status for every request.
You could set the registered_delivery flag in submit_sm to 1 and listen for incoming deliver_sm PDUs, so you get the delivery reports from them, instead of querying them for every message you send.
I solved my problem by using QuerySmResp to get the Delivery Report.
This is the code to check for the Delivery Status of the SMS Message:
QuerySmResp qresp = client.Query(_MessageID, SrcTon, SrcNpi, SrcAddr);
string _Delivery = qresp.MessageState.ToString();
MessageState property will show the status of the message and it's members are:
None
Enroute
Delivered
Expired
Deleted
Undeliverable
Accepted
Unknown
Rejected
I have a weird situation and I'm stuck.
I created push notification in my WindowsPhone application.
After some time my channelUri has expired and now I can't create new one, because the code responsible for that returns the same invalid channel Uri.
What am I doing wrong ?
_pushChannel = HttpNotificationChannel.Find(channelName); //returns null
if (null == _pushChannel)
{
_pushChannel = new HttpNotificationChannel(channelName); //returns channel with expired channelUri
_pushChannel.Open();
}
I also tried using Close() method, but it didn't help anyway.
Any help will be much appreciated.
When a channel expires and a new one is issued you will normally get the same URI back. This is to be expected.
What will be different is that the channel will be been enabled again. If you discover that when you next send to a notification the channel is reported as expired then check what you are sending as invalid payloads will cause the channel to expire when upon sending.