Monitoring a mailbox for new email message using EWS Managed API - monitoring

I'm working on a task which I never worked in earlier.
Task: Monitor a specific mailbox inbox on exchange server 2007. Iterate through all email messages(Just email messages), do some processing and move to a specific folder under same mailbox.
Work I did
// Create the binding
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//service.Credentials = new WebCredentials("mailbox", "password", "mailbox#something.com");
service.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["ExchangeUsername"].ToString(), ConfigurationManager.AppSettings["ExchangePassword"].ToString(), "something/domain");
// Set the url.
//service.AutodiscoverUrl("mailbox#something.com");
service.Url = new Uri(ServiceUrl);
ItemView view = new ItemView(10);
view.Traversal = ItemTraversal.Shallow;
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
//searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.ItemClass, "MessageType"));
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "test to be deleted"));
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, view);
For some reason i always get results.items.count = 9, but there is only one EmailMessage in Mailbox#something.com. Am i doing any thing wrong in searching. If inbox had 5 emails, then i should get count as 5 and loop through the 5 emails. Is there a way to query just the email messages? Any help is appreciated. Thank you.

I answered my own questiona a while ago, but forgot to update here. So when i said count was not matching, it was monitoring mailbox of impersonating account. Coincidentally, the impersonating account has a mailbox.

Related

Example of Reading User's Email Using Microsoft Graph

I'm creating a C# .Net Core 2.0 console application to read a specific user's email. I successfully got this sample console application working. So authentication is working. I added permissions to Read all User's email. I looked at the API docs and I can't see examples of reading a user's email. Plenty of send examples. Any help appreciated.
Thanks for posting. I got this to work if I comment out the Filter:
GraphServiceClient client = GetAuthenticatedClient();
string subject = "RE: ACTION NEEDED:";
string dt = "2018-10-5T00:00:00";
IUserMessagesCollectionPage msgs = client.Users["UserName#CompanyName.com"].Messages.Request()
//.Filter($"receivedDateTime ge '{dt}'") // Invalid filter
.Filter($"startswith(subject, '{subject}') and receivedDateTime gt {dt}")
.Select(m => new { m.Subject, m.ReceivedDateTime, m.From, m.Body })
.Top(100)
.GetAsync().Result;
int msgCnt = msgs.Count;
I posted something about getting filter to work. startswith works but the date filter fails.
To get each one's mail.
var users = graphClient.Users.Request().GetAsync().Result;
To get the specific user's mail:
List<QueryOption> options = new List<QueryOption>
{
new QueryOption("$filter", "startswith(displayName,'the specific user's mail')")
};
var users= await graphClient.Users.Request(options).GetAsync();
//Or
var users = await graphClient.Users.Request().Filter("startswith(displayName,'help')").GetAsync();
Get Mail:
foreach (var item in users)
{
string currentMail=item.Mail;
}
Update 2018-10-7
For your updated post:
You can use the following API to filter the mails:
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$filter=ReceivedDateTime ge 2018-10-04 and startswith(subject,'{subject}')

UCWA MyOnlineMeeting attendees requirements? External attendees

I'm currently trying to develop an application that creates Skype meetings.
I'm leveraging the C# UCWA SDK and developing against Skype for Business online.
Meeting creation works fine if I only include people from the tenant in attendees, as soon as I include people not from the tenant in the meeting I get this error message:
{"code":"BadRequest","subcode":"ParameterValidationFailure","message":"Please check what you entered and try again.","debugInfo":{"diagnosticsCode":"2"}}
Here is my code sample
var meeting = new MyOnlineMeeting()
{
AccessLevel = AccessLevel.Everyone,
Attendees = new string[] { $"sip:{Settings.SkypeUserEmail}" }, //Adding anybody else than the service account makes it fail for now
Subject = series.Subject,
ExpirationTime = DateTime.Now.AddDays(3),
AutomaticLeaderAssignment = AutomaticLeaderAssignment.SameEnterprise,
Leaders = series.Organizers.Select(x => $"sip:{x.EmailAddress}").ToArray(),
LobbyBypassForPhoneUsers = LobbyBypassForPhoneUsers.Enabled,
PhoneUserAdmission = PhoneUserAdmission.Disabled
};
var dialIn = await client.OnlineMeetings.GetPhoneDialInInformation();
var meetings = await client.OnlineMeetings.GetMyOnlineMeetings();
var result = await meetings.Create(meeting);
Adding external users to the organizers properties works fine though.
My question is: how can I add external attendees to the meeting I'm creating? Is there anything specific around attendees?
After a few exchanges on the Microsoft Skype for Business MVP's private distribution list, it appears that attendees have to be part of the organization or otherwise the call will fail.
Submitted a Pull Request to update the latest version of the documentation

Twilio StatusCallBack Incorrect

I'm developing a vb net application using twilio api.
This is my code:
Twilio.TwilioClient.Init(AccountSid, AuthToken)
Dim call_to As PhoneNumber = New PhoneNumber("...")
Dim call_from As PhoneNumber = New PhoneNumber("...")
Dim call_option As CreateCallOptions = New CreateCallOptions(call_to, call_from)
call_option.Method = "Get"
call_option.Timeout = 25
call_option.Url = New Uri(ws_url & "/GET_CALL_XML" & ws_parameter)
call_option.StatusCallback = New Uri(ws_url & "/GET_CALL_FEEDBACK" & ws_parameter)
call_option.FallbackUrl = New Uri(ws_url & "/GET_CALL_ERROR" & ws_parameter)
call_option.StatusCallbackEvent.Add("answered")
call_option.StatusCallbackEvent.Add("completed")
Dim call_ As CallResource = CallResource.Create(call_option)
The call is successfully performed.
Now the problem is:
if the user answer the call, i receive the StatusCallBack with "callstatus"="in-progress"
if the user refuse the call, i receive the StatusCallBack with "callstatus"="in-progress" equally
How can i know if the user really answer the call?
Thank you
Twilio developer evangelist here.
If the user actually answers the call, then you will get a webhook to the Url that you set, in your example, the one with the path /GET_CALL_XML.
If the user refuses the call then you will not receive a webhook to that URL.

ASP.NET MVC Leave a Copy of Email on Server

I have a ASP.NET MVC 4 project with EF. I' m using System.Net.Mail to send emails programmatically.
MailMessage msg = new MailMessage();
msg.From = new MailAddress("JohnDoe#gmail.com", "John Doe");
msg.To.Add(new MailAddress("janedoe#gmail.com"));
msg.Subject = "Hi.";
msg.Body= "Aleluia";
var smtp = new SmtpClient("mail.johndoe.com", 999);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new System.Net.NetworkCredential("JohnDoe#gmail.com", "johnspass");
smtpclient.Send(msg);
Q : How can I save a copy of this email in John Doe's Sent Items ? If I have Outlook can I use this ?
Q2 : How can I elaborate this email's body(to add a image in the left top corner, to add a bolded text) ?
I'm not sure if you can achieve this from a website, unless you have a way to manipulate a backend mail server and have access to manipulate users mailboxes.
The way outlook does this is by pushing any new sent email to the Sent Items folder and then it syncronizes the content with Exchange Server.
I also think Exchange server provides the API to achieve this behavior but your website would have to run under Windows Authentication to access and manipulate each user mailbox. I dont think is a good idea to give access to individual mailboxes to a global account (in this case the website pool identity account). You also might want to look into Exchange Web Services (2007 or greater).
This has been my experience with Exchange Server, I might be unaware of another allowed behavior and dont know anything about other mail servers in terms of APIs.

find signature is required or not using shipment API (USPS, UPS, DHL, FeDex)

I am integrating the Carrier (USPS, UPS, DHL, FeDex) API with my application.
For that i need to find different statuses for that shipment like is it delivered or not, which is getting me properly.
Similarly, i need to check whether the shipment required the signature or not?
How do i came to know this using the different API?
Regards,
Salil Gaikwad
Not all APIs support the same functionality. All will tell you the current status and some will provide the shipper/recipient information but I don't believe any will tell you if it was sent signature required.
E.g. for FedEx if you want to know about parcel's tracking events (delivered or not, any problems, delivery time and many other info) use this service endpoint - https://ws.fedex.com:443/web-services/track. The request to FedEx will be look like this (C# sample):
TrackRequest request = new TrackRequest();
request.WebAuthenticationDetail = new WebAuthenticationDetail();
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential()
{
Key = "ApiKey",
Password = "PasswordKey"
};
request.ClientDetail = new ClientDetail
{
AccountNumber = "...",
MeterNumber = "..."
};
request.TransactionDetail = new TransactionDetail();
request.PackageIdentifier = new TrackPackageIdentifier();
request.PackageIdentifier.Value = "parcel tracking number";
request.PackageIdentifier.Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG;
request.IncludeDetailedScans = true;
request.IncludeDetailedScansSpecified = true;
request.Version = new VersionId();
When you receive from FedEx - TrackReply, you should check TrackDetails array. There will be tracking info. As for other carriers, the common idea is the same. Almost every carrier use tracking number.

Resources