private static Microsoft.Graph.Message CreateMessage() { var mailboxHelper = new MailboxHelper(_graphServiceClient); var message = new Microsoft.Graph.Message { Subject = "Large attachment is here", Importance = Importance.Low, Body = new ItemBody { ContentType = BodyType.Html, Content = "Why can't you make small <b>attachments</b>!" }, ToRecipients = new List <Recipient>() { new Recipient { EmailAddress = new EmailAddress { Address = "*****@*****.**" } } } }; message = mailboxHelper.CreateMessage(message, userId).Result; Console.WriteLine("Message Id: " + message.Id); return(message); }
// Send mail on behalf of the current user. public async Task <ActionResult> SendEmail() { if (string.IsNullOrEmpty(Request.Form["email-address"])) { ViewBag.Message = Resource.Graph_SendMail_Message_GetEmailFirst; return(View("Graph")); } try { // Initialize the GraphServiceClient. GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient(); // Build the email message. Microsoft.Graph.Message message = await graphService.BuildEmailMessage(graphClient, Request.Form["recipients"], Request.Form["subject"]); // Send the email. await graphService.SendEmail(graphClient, message); // Reset the current user's email address and the status to display when the page reloads. ViewBag.Email = Request.Form["email-address"]; ViewBag.Message = Resource.Graph_SendMail_Success_Result; return(View("Graph")); } catch (ServiceException se) { if (se.Error.Code == Resource.Error_AuthChallengeNeeded) { return(new EmptyResult()); } return(RedirectToAction("Index", "Error", new { message = Resource.Error_Message + Request.RawUrl + ": " + se.Error.Message })); } }
public async Task <MMM.EventMessage> CreateInvitationResponse(Meeting meeting, string action) { var invite = await GetEventInvitation(meeting); if (invite == null) { return(null); } var builder = _graphClient.Me.Messages[invite.Id]; Microsoft.Graph.Message message = null; switch (action) { case OData.Reply: message = await builder.CreateReply().Request().PostAsync(); break; case OData.ReplyAll: message = await builder.CreateReplyAll().Request().PostAsync(); break; case OData.Forward: message = await builder.CreateForward().Request().PostAsync(); break; } return(message.ConvertObject <MMM.EventMessage>()); }
// Send Message private static Microsoft.Graph.Message SendMessage(Microsoft.Graph.Message message) { var mailboxHelper = new MailboxHelper(_graphServiceClient); mailboxHelper.SendMessage(message, userId); Console.WriteLine("Message sent"); return(message); }
public static async Task SendMailAsync(string accessToken, string subject, string to, string body) { var graphClient = new GraphServiceClient( new DelegateAuthenticationProvider( async(requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); })); try { string Mails = to; var toRecipients = Mails.Split(' '); List <Recipient> a = new List <Recipient>(); foreach (var address in toRecipients) { Recipient b = new Recipient { EmailAddress = new EmailAddress { Address = address, } }; a.Add(b); } var message = new Message { Subject = subject, Body = new ItemBody { ContentType = BodyType.Text, Content = body }, ToRecipients = a, }; await graphClient.Me .SendMail(message, null) .Request() .PostAsync(); } catch (ServiceException ex) { } }
// Create upload session private static UploadSession CreateUploadSession(Microsoft.Graph.Message message, string attachmentName, long attachmentSize) { var mailboxHelper = new MailboxHelper(_graphServiceClient); var attachmentItem = new AttachmentItem() { AttachmentType = AttachmentType.File, Name = attachmentName, Size = attachmentSize }; var uploadSession = mailboxHelper.CreateUploadSession(message, userId, attachmentItem).Result; Console.WriteLine("Upload URL: " + uploadSession.UploadUrl); return(uploadSession); }
private MSMessage MapMimeMessageToMSMessage(MimeMessage mime) { MSMessage message = new MSMessage { ReceivedDateTime = mime.Date }; if (mime.To != null) { var to = new List <Recipient>(); foreach (var address in mime.To) { to.Add(new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)address).Address, Name = address.Name == string.Empty ? ((MailboxAddress)address).Address : address.Name, }, }); } message.ToRecipients = to; } if (mime.From != null && mime.From.Count > 0) { message.From = new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)mime.From[0]).Address, // mime.From[0].ToString() Name = mime.From[0].Name == string.Empty ? ((MailboxAddress)mime.From[0]).Address : mime.From[0].Name, }, }; message.Sender = new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)mime.From[0]).Address, Name = mime.From[0].Name == string.Empty ? ((MailboxAddress)mime.From[0]).Address : mime.From[0].Name, }, }; } if (mime.Sender != null) { message.Sender = new Recipient { EmailAddress = new EmailAddress { Address = mime.Sender.Address, Name = mime.Sender.Name == string.Empty ? mime.Sender.Address : mime.Sender.Name, }, }; } if (mime.Subject != null) { message.Subject = mime.Subject; } if (mime.Body != null) { var textBody = mime.TextBody; message.Body = new ItemBody { Content = textBody, ContentType = BodyType.Text, }; } if (mime.Cc != null) { var cc = new List <Recipient>(); foreach (var address in mime.Cc) { cc.Add(new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)address).Address, Name = address.Name == string.Empty ? ((MailboxAddress)address).Address : address.Name, }, }); } message.CcRecipients = cc; } if (mime.ReplyTo != null) { var replyTo = new List <Recipient>(); foreach (var address in mime.ReplyTo) { replyTo.Add(new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)address).Address, Name = address.Name == string.Empty ? ((MailboxAddress)address).Address : address.Name, }, }); } message.ReplyTo = replyTo; } // Set importance switch (mime.Importance) { case MessageImportance.Low: message.Importance = Importance.Low; break; case MessageImportance.Normal: message.Importance = Importance.Normal; break; case MessageImportance.High: message.Importance = Importance.High; break; default: break; } // Set attachment status if (mime.Attachments != null && mime.Attachments.Count() > 0) { message.HasAttachments = true; } return(message); }
private MSMessage MapMimeMessageToMSMessage(MimeMessage mime) { MSMessage message = new MSMessage(); message.ReceivedDateTime = mime.Date; if (mime.To != null) { var to = new List <Recipient>(); foreach (var address in mime.To) { to.Add(new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)address).Address, Name = address.Name == string.Empty ? ((MailboxAddress)address).Address : address.Name, }, }); } message.ToRecipients = to; } if (mime.From != null && mime.From.Count > 0) { message.From = new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)mime.From[0]).Address, // mime.From[0].ToString() Name = mime.From[0].Name == string.Empty ? ((MailboxAddress)mime.From[0]).Address : mime.From[0].Name, }, }; message.Sender = new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)mime.From[0]).Address, Name = mime.From[0].Name == string.Empty ? ((MailboxAddress)mime.From[0]).Address : mime.From[0].Name, }, }; } if (mime.Sender != null) { message.Sender = new Recipient { EmailAddress = new EmailAddress { Address = mime.Sender.Address, Name = mime.Sender.Name == string.Empty ? mime.Sender.Address : mime.Sender.Name, }, }; } if (mime.Subject != null) { message.Subject = mime.Subject; } if (mime.Body != null) { var textBody = mime.BodyParts.OfType <TextPart>().FirstOrDefault(); message.Body = new ItemBody { Content = textBody.Text, ContentType = BodyType.Text, }; } if (mime.Cc != null) { var cc = new List <Recipient>(); foreach (var address in mime.Cc) { cc.Add(new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)address).Address, Name = address.Name == string.Empty ? ((MailboxAddress)address).Address : address.Name, }, }); } message.CcRecipients = cc; } if (mime.ReplyTo != null) { var replyTo = new List <Recipient>(); foreach (var address in mime.ReplyTo) { replyTo.Add(new Recipient { EmailAddress = new EmailAddress { Address = ((MailboxAddress)address).Address, Name = address.Name == string.Empty ? ((MailboxAddress)address).Address : address.Name, }, }); } message.ReplyTo = replyTo; } return(message); }
async Task SendEmailAfterRepairCompleted() { var recipient = new Recipient { EmailAddress = new EmailAddress { Address = CurrentIncident.GetProperty().GetEmail() } }; var dispatcherRecipient = new Recipient { EmailAddress = new EmailAddress { Address = Constants.DISPATCHEREMAIL } }; var subject = string.Format("Repair Report - {0} - {1:MM/dd/yyyy}", CurrentIncident.GetProperty().GetTitle(), DateTime.Now); var body = string.Format("The incident found during a recent inspection on you property has been repaired. Photographs taken during the inspection and after the repair are attached to this email." + "<br/>" + "<br/><b>Property Name:</b> {0}" + "<br/><b>Property Address:</b> {1}" + "<br/>" + "<br/><b>Inspection Date:</b> {2}" + "<br/><b>Incident Type:</b> {3}" + "<br/><b>Room:</b> {4}" + "<br/><b>Comments from the inspector:</b><br/>{5}" + "<br/><br/><b>Incident reported:</b> {6}" + "<br/>" + "<br/><b>Repair Date:</b> {7:MM/dd/yyyy}" + "<br/><b>Comments from repair person:</b><br/>{8}" + "<br/>" + "<br/><b>Attachments:</b>(Inspection & Repair Photos) - Email attachments are not supported at this time in Xamarin app, therefore no files are attached." + "<br/>" + "<p>Incident ID: <span id='x_IncidentID'>{9}</span></p>" + "<p>Property ID: <span id='x_PropertyID'>{10}</span></p>", CurrentIncident.GetProperty().GetTitle(), CurrentIncident.GetProperty().GetAddress1(), CurrentIncident.GetInspection().GetDateTime(), CurrentIncident.GetType(), CurrentIncident.GetRoom().GetTitle(), CurrentIncident.GetInspectorIncidentComments(), CurrentIncident.GetDate(), DateTime.Now, CurrentIncident.GetRepairComments(), CurrentIncident.GetId(), CurrentIncident.GetProperty().GetId() ); var message = new Microsoft.Graph.Message { ToRecipients = new [] { recipient }, CcRecipients = new [] { dispatcherRecipient }, Subject = subject, Body = new ItemBody { Content = body, ContentType = BodyType.HTML } }; process = ProgressDialog.Show(this, "Processing", "Sending email..."); //Currently, the following 2 lines of code must be executed before the SendMailAsync //method is called. If the call the return the user's photo is not executed //the SendMailAsync method will not successfully send the email. This is a known //issue and this sample will be adjusted accordingly once this issue is resolved. var photo = await App.GraphService.Me.UserPhoto.ExecuteAsync(); var pid = photo.Id.ToString(); await App.GraphService.Me.SendMailAsync(message, true); process.Dismiss(); }
public async void CreateNewMessage() { try { // split out the different email addresses and add to collection char[] delim = { ';' }; // handle To: string[] toArray = tbToRecipients.Text.Split(delim); foreach (var to in toArray) { AddRecipToCollection(to, toRecipients); } // handle Cc: string[] ccArray = tbCC.Text.Split(delim); foreach (var cc in toArray) { AddRecipToCollection(cc, ccRecipients); } // handle Bcc: string[] bccArray = tbBcc.Text.Split(delim); foreach (var bcc in toArray) { AddRecipToCollection(bcc, bccRecipients); } // create the item body ItemBody body = new ItemBody(); body.Content = rtbBody.Text; body.ContentType = BodyType.Html; // create the message object and add the properties Microsoft.Graph.Message msg = new Microsoft.Graph.Message(); msg.Subject = tbSubject.Text; msg.Body = body; msg.ToRecipients = toRecipients; msg.CcRecipients = ccRecipients; msg.BccRecipients = bccRecipients; // set importance if (cbxImportance.Text == "Normal") { msg.Importance = Importance.Normal; } else if (cbxImportance.Text == "High") { msg.Importance = Importance.High; } else { msg.Importance = Importance.Low; } // setup the attachment collection if (dgAttachments.Rows.Count > 0) { // setup the attachments collection msg.Attachments = new MessageAttachmentsCollectionPage(); // add attachments foreach (DataGridViewRow row in dgAttachments.Rows) { if (row.Cells[0].Value != null) { // create the file attachment from the file path FileAttachment file = new FileAttachment(); byte[] array = System.IO.File.ReadAllBytes(row.Cells[0].Value.ToString()); file.ContentBytes = array; file.Name = row.Cells[1].Value.ToString(); file.ContentType = row.Cells[2].Value.ToString(); file.ContentId = row.Cells[4].Value.ToString(); file.IsInline = false; file.ODataType = row.Cells[6].Value.ToString(); // add it to the message msg.Attachments.Add(file); } } } // log the request info sdklogger.Log(graphClient.Me.SendMail(msg, true).Request().GetHttpRequestMessage().Headers.ToString()); sdklogger.Log(graphClient.Me.SendMail(msg, true).Request().GetHttpRequestMessage().RequestUri.ToString()); // send the new message await graphClient.Me.SendMail(msg, true).Request().PostAsync(); } catch (Exception ex) { sdklogger.Log("NewMessageSend Failed: "); sdklogger.Log(ex.Message); sdklogger.Log(ex.StackTrace); } finally { // close the form Close(); } }
async Task SendEmailAfterRepairCompleted() { var recipient = new Recipient { EmailAddress = new EmailAddress { Address = CurrentIncident.GetProperty ().GetEmail () } }; var dispatcherRecipient = new Recipient { EmailAddress = new EmailAddress { Address = Constants.DISPATCHEREMAIL } }; var subject = string.Format ("Repair Report - {0} - {1:MM/dd/yyyy}", CurrentIncident.GetProperty ().GetTitle (), DateTime.Now); var body = string.Format ("The incident found during a recent inspection on you property has been repaired. Photographs taken during the inspection and after the repair are attached to this email." + "<br/>" + "<br/><b>Property Name:</b> {0}" + "<br/><b>Property Address:</b> {1}" + "<br/>" + "<br/><b>Inspection Date:</b> {2}" + "<br/><b>Incident Type:</b> {3}" + "<br/><b>Room:</b> {4}" + "<br/><b>Comments from the inspector:</b><br/>{5}" + "<br/><br/><b>Incident reported:</b> {6}" + "<br/>" + "<br/><b>Repair Date:</b> {7:MM/dd/yyyy}" + "<br/><b>Comments from repair person:</b><br/>{8}" + "<br/>" + "<br/><b>Attachments:</b>(Inspection & Repair Photos) - Email attachments are not supported at this time in Xamarin app, therefore no files are attached." + "<br/>" + "<p>Incident ID: <span id='x_IncidentID'>{9}</span></p>" + "<p>Property ID: <span id='x_PropertyID'>{10}</span></p>", CurrentIncident.GetProperty ().GetTitle (), CurrentIncident.GetProperty ().GetAddress1 (), CurrentIncident.GetInspection ().GetDateTime (), CurrentIncident.GetType (), CurrentIncident.GetRoom ().GetTitle (), CurrentIncident.GetInspectorIncidentComments (), CurrentIncident.GetDate (), DateTime.Now, CurrentIncident.GetRepairComments (), CurrentIncident.GetId (), CurrentIncident.GetProperty ().GetId () ); var message = new Microsoft.Graph.Message { ToRecipients = new []{ recipient }, CcRecipients = new []{ dispatcherRecipient }, Subject = subject, Body = new ItemBody{ Content = body, ContentType = BodyType.HTML } }; process = ProgressDialog.Show(this, "Processing", "Sending email..."); //Currently, the following 2 lines of code must be executed before the SendMailAsync //method is called. If the call the return the user's photo is not executed //the SendMailAsync method will not successfully send the email. This is a known //issue and this sample will be adjusted accordingly once this issue is resolved. var photo = await App.GraphService.Me.UserPhoto.ExecuteAsync(); var pid = photo.Id.ToString(); await App.GraphService.Me.SendMailAsync(message, true); process.Dismiss(); }
async Task SendEmailAfterRepairCompleted() { var graphToken = await AuthenticationHelper.GetGraphAccessTokenAsync(this); var recipient = CurrentIncident.GetProperty().GetEmail(); var dispatcherRecipient = Constants.DISPATCHEREMAIL; var subject = string.Format("Repair Report - {0} - {1:MM/dd/yyyy}", CurrentIncident.GetProperty().GetTitle(), DateTime.Now); var bodyContent = string.Format("The incident found during a recent inspection on you property has been repaired. Photographs taken during the inspection and after the repair are attached to this email." + "<br/>" + "<br/><b>Property Name:</b> {0}" + "<br/><b>Property Address:</b> {1}" + "<br/>" + "<br/><b>Inspection Date:</b> {2}" + "<br/><b>Incident Type:</b> {3}" + "<br/><b>Room:</b> {4}" + "<br/><b>Comments from the inspector:</b><br/>{5}" + "<br/><br/><b>Incident reported:</b> {6}" + "<br/>" + "<br/><b>Repair Date:</b> {7:MM/dd/yyyy}" + "<br/><b>Comments from repair person:</b><br/>{8}" + "<br/>" + "<br/><b>Attachments:</b>(Inspection & Repair Photos) - Email attachments are not supported at this time in Xamarin app, therefore no files are attached." + "<br/>" + "<p>Incident ID: <span id='x_IncidentID'>{9}</span></p>" + "<p>Property ID: <span id='x_PropertyID'>{10}</span></p>", CurrentIncident.GetProperty().GetTitle(), CurrentIncident.GetProperty().GetAddress1(), CurrentIncident.GetInspection().GetDateTime(), CurrentIncident.GetType(), CurrentIncident.GetRoom().GetTitle(), CurrentIncident.GetInspectorIncidentComments(), CurrentIncident.GetDate(), DateTime.Now, CurrentIncident.GetRepairComments(), CurrentIncident.GetId(), CurrentIncident.GetProperty().GetId() ); var message = new Microsoft.Graph.Message { Subject = subject, Body = new ItemBody { ContentType = BodyType.Html, Content = bodyContent }, ToRecipients = new Recipient[] { new Recipient { EmailAddress = new EmailAddress { Address = dispatcherRecipient } } }, CcRecipients = new Recipient[] { new Recipient { EmailAddress = new EmailAddress { Address = recipient } } } }; var requestBuilder = App.GraphService.Me.SendMail(message, true); var request = requestBuilder.Request(); request.ContentType = "application/json"; request.Headers.Add(new HeaderOption("Authorization", "Bearer " + graphToken)); process = ProgressDialog.Show(this, "Processing", "Sending email..."); await request.PostAsync(); process.Dismiss(); }