Sending email using EWS in c# from shared mailbox

Sending email using EWS in c# from shared mailbox

To send an email using Exchange Web Services (EWS) in C# from a shared mailbox, you can follow these steps:

  • Create a new instance of the ExchangeService class and set the credentials for the shared mailbox. For example:
var service = new ExchangeService(); service.Credentials = new NetworkCredential("sharedmailbox@example.com", "password"); 
  • Set the URL for the Exchange Web Services endpoint. For example:
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx"); 
  • Create a new EmailMessage object and set its properties, such as the subject, body, and recipients. For example:
var message = new EmailMessage(service); message.Subject = "Test Email"; message.Body = new MessageBody("This is a test email"); message.ToRecipients.Add("recipient@example.com"); 
  • Set the sender of the email message to the shared mailbox. For example:
message.From = new Mailbox("sharedmailbox@example.com"); 
  • Send the email message using the SendAndSaveCopy() method. For example:
message.SendAndSaveCopy(); 

This will send the email message from the shared mailbox using EWS in C#.

Examples

  1. "EWS send email from shared mailbox in C#"

    • Description: Understand how to send an email using Exchange Web Services (EWS) in C# specifically from a shared mailbox. Here's a basic example:

      using Microsoft.Exchange.WebServices.Data; ExchangeService service = new ExchangeService(); service.Credentials = new WebCredentials("sharedMailbox@company.com", "password"); service.AutodiscoverUrl("sharedMailbox@company.com"); EmailMessage email = new EmailMessage(service); email.Subject = "Subject"; email.Body = new MessageBody("Email body"); email.ToRecipients.Add("recipient@example.com"); email.Send(); 
  2. "C# EWS send email as shared mailbox delegate"

    • Description: Explore how to send an email through EWS in C# on behalf of a shared mailbox using a delegate:

      // ... (same setup as the first example) email.From = new EmailAddress("delegateUser@company.com", "Delegate User"); email.Send(); 
  3. "C# EWS send email with attachments from shared mailbox"

    • Description: Extend your knowledge to send emails with attachments using EWS in C# from a shared mailbox:

      // ... (same setup as the first example) EmailMessage email = new EmailMessage(service); email.Subject = "Subject"; email.Body = new MessageBody("Email body"); // Attach a file email.Attachments.AddFileAttachment("path/to/your/file.txt"); email.ToRecipients.Add("recipient@example.com"); email.Send(); 
  4. "C# EWS send HTML email from shared mailbox"

    • Description: Send HTML-formatted emails through EWS in C# from a shared mailbox:

      // ... (same setup as the first example) EmailMessage email = new EmailMessage(service); email.Subject = "Subject"; email.Body = new MessageBody(BodyType.HTML, "<html><body><h1>Email body with HTML</h1></body></html>"); email.ToRecipients.Add("recipient@example.com"); email.Send(); 
  5. "C# EWS send email with custom properties from shared mailbox"

    • Description: Learn how to include custom properties when sending emails through EWS in C# from a shared mailbox:

      // ... (same setup as the first example) ExtendedPropertyDefinition customProperty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "CustomProperty", MapiPropertyType.String); email.SetExtendedProperty(customProperty, "CustomValue"); email.Send(); 
  6. "C# EWS send email as shared mailbox and save to sent items"

    • Description: Explore how to send an email as a shared mailbox in C# through EWS and save it to the Sent Items folder:

      // ... (same setup as the first example) email.SendAndSaveCopy(); 
  7. "C# EWS send meeting request from shared mailbox"

    • Description: Learn how to send a meeting request through EWS in C# from a shared mailbox:

      // ... (same setup as the first example) Appointment meetingRequest = new Appointment(service); meetingRequest.Subject = "Meeting Subject"; meetingRequest.Body = new MessageBody("Meeting body"); meetingRequest.Location = "Meeting Room"; meetingRequest.Start = DateTime.Now.AddHours(1); meetingRequest.End = meetingRequest.Start.AddHours(2); meetingRequest.RequiredAttendees.Add("attendee@example.com"); meetingRequest.Save(); meetingRequest.Send(); 
  8. "C# EWS send email with priority from shared mailbox"

    • Description: Set the priority of an email when sending it through EWS in C# from a shared mailbox:

      // ... (same setup as the first example) email.Importance = Importance.High; // or Importance.Low email.Send(); 

More Tags

video-player writer material-table ld cmake uitextfielddelegate fusioncharts php-ini recaptcha-v3 python-unicode

More C# Questions

More Geometry Calculators

More Statistics Calculators

More Chemical reactions Calculators

More Mortgage and Real Estate Calculators