/// <summary> /// Shows how to retrieve an email from IMAP server using OpenEntityStream method /// </summary> public static void RetrieveEmailUsingOpenEntityStreamIMAP() { //ExStart:RetrieveEmailUsingOpenEntityStream // Create connection info var info = EmailConnectionInfo.CreateImapConnectionInfo(@"imap-mail.outlook.com", 995, "username", "password"); // Create an email container using (var container = new EmailContainer(info)) { // Iterate over emails foreach (var entity in container.Entities) { // Create a stream with content of email var stream = container.OpenEntityStream(entity); // or var stream = entity.OpenStream(); // Create a text extractor for email using (var extractor = new EmailTextExtractor(stream)) { // Extract all the text from email Console.WriteLine(extractor.ExtractAll()); } } } //ExEnd:RetrieveEmailUsingOpenEntityStreamPOP3 }
/// <summary> /// Shows how to retrieve an email from Microsoft exchange server using OpenEntityStream method /// </summary> public static void RetrieveEmailUsingOpenEntityStream() { //ExStart:RetrieveEmailUsingOpenEntityStream // Create connection info var info = EmailConnectionInfo.CreateEwsConnectionInfo(@"https://outlook.office365.com/ews/exchange.asmx", "username", "password"); // Create an email container using (var container = new EmailContainer(info)) { // Iterate over emails foreach (var entity in container.Entities) { // Create a stream with content of email var stream = container.OpenEntityStream(entity); // or var stream = entity.OpenStream(); // Create a text extractor for email using (var extractor = new EmailTextExtractor(stream)) { // Extract all the text from email Console.WriteLine(extractor.ExtractAll()); } } } //ExEnd:RetrieveEmailUsingOpenEntityStream }
/// <summary> /// Shows how to retrieve emails from Microsoft exchange server using Entity property /// </summary> public static void RetrieveEmailsUsingEntity() { //ExStart:RetrieveEmailsUsingEntity // Create connection info var info = EmailConnectionInfo.CreateEwsConnectionInfo(@"https://outlook.office365.com/ews/exchange.asmx", "username", "password"); // Create an email container using (var container = new EmailContainer(info)) { // Iterate over emails foreach (var entity in container.Entities) { Console.WriteLine("Folder: " + entity.Path.ToString()); // A folder at server Console.WriteLine("Subject: " + entity[MetadataNames.Subject]); // A subject of email Console.WriteLine("From: " + entity[MetadataNames.EmailFrom]); // "From" address Console.WriteLine("To: " + entity[MetadataNames.EmailTo]); // "To" addresses } } //ExEnd:RetrieveEmailsUsingEntity }
public async Task SendAsync(IdentityMessage message) { string pepiMainEndpoint = ConfigurationManager.AppSettings["PEPI_MAIL_ENDPOINT"]; string pepiApiKey = ConfigurationManager.AppSettings["PEPI_MAIL_KEY"]; var mainContainer = new EmailContainer() { Content = message.Body, Subject = message.Subject, ReplyToId = "*****@*****.**", Personalizations = new MailPersonalization[] { new MailPersonalization { Recipient = message.Destination } }, From = new MailFrom { FromEmail = "*****@*****.**", FromName = "Identity 2.0 Admin" } }; string mailString = JsonConvert.SerializeObject(mainContainer, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore }); var client = new RestClient(pepiMainEndpoint); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("api_key", pepiApiKey); request.AddParameter("application/json", mailString, ParameterType.RequestBody); IRestResponse response = await client.ExecuteAsync(request); return; }
/// <summary> /// Shows how to retrieve emails from IMAP server using Entity property /// </summary> public static void RetrieveEmailsUsingEntityIMAP() { //ExStart:RetrieveEmailsUsingEntity // Create connection info var info = EmailConnectionInfo.CreateImapConnectionInfo(@"imap-mail.outlook.com", 995, "username", "password"); // Create an email container using (var container = new EmailContainer(info)) { // Iterate over emails foreach (var entity in container.Entities) { Console.WriteLine("Folder: " + entity.Path.ToString()); // A folder at server Console.WriteLine("Subject: " + entity[MetadataNames.Subject]); // A subject of email Console.WriteLine("From: " + entity[MetadataNames.EmailFrom]); // "From" address Console.WriteLine("To: " + entity[MetadataNames.EmailTo]); // "To" addresses Console.WriteLine("Date: " + entity.Date); Console.WriteLine("Size: " + entity.Size); } } //ExEnd:RetrieveEmailsUsingEntity }