Last active
January 3, 2023 09:45
-
-
Save aspose-com-gists/6e5185a63aec6fd70d83098e82b06a32 to your computer and use it in GitHub Desktop.
Aspose.Email for .NET
This gist exceeds the recommended number of files (~10).
To access all files, please clone this gist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gists of Aspose.Email for .NET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration> | |
<configSections> | |
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | |
<section name="Aspose.Email.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> | |
</sectionGroup> | |
</configSections> | |
<applicationSettings> | |
<Aspose.Email.Properties.Settings> | |
<setting name="SmtpDiagnosticLog" serializeAs="String"> | |
<value>Aspose.Email.SMTP.log</value> | |
</setting> | |
</Aspose.Email.Properties.Settings> | |
</applicationSettings> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reply-To: reply@reply.com | |
From: sender@sender.com | |
To: guangzhou@guangzhoo.com | |
Subject: test mail | |
Date: 6 Mar 2006 8:2:2 +0800 | |
X-Mailer: Aspose.Email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Examples-CSharp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ImapClient client = new ImapClient("imap.domain.com", "username", "password"); | |
client.EnableSsl = true; | |
client.SecurityMode = ImapSslSecurityMode.Implicit; | |
// Set proxy address, port and proxy | |
string proxyAddress = "192.168.203.142"; | |
int proxyPort = 1080; | |
SocksProxy proxy = new SocksProxy(proxyAddress, proxyPort, Aspose.Email.Protocols.Proxy.SocksVersion.SocksV5); | |
client.SocksProxy = proxy; | |
client.SelectFolder("Inbox"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
static void Main(string[] args) | |
{ | |
// The authorizationCode should be replaced with your value. To get authorizationCode use the URL bellow: https://accounts.google.com/o/oauth2/auth?redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=929645059575.apps.googleusercontent.com&scope=https%3A%2F%2Fmail.google.com%2F | |
string authorizationCode = "4/zx4_I4ZhhUdmgLdsejpjeMkwAAMs.kk7o1Qx9U28VOl05ti8ZT3Y1uIlidQI"; // authorizationCode should be replaced with new value !!!!!!! | |
string accessToken = GetAccessToken(authorizationCode); | |
AccessSMTPServer(accessToken); | |
AccessIMAPServer(accessToken); | |
} | |
static void AccessSMTPServer(string accessToken) | |
{ | |
MailMessage message = new MailMessage("user1@testaccount1913.narod2.ru","user1@testaccount1913.narod2.ru","NETWORKNET-33499 - " + Guid.NewGuid().ToString(),"Access to SMTP servers using OAuth"); | |
using (SmtpClient client = new SmtpClient("smtp.gmail.com", 587, "user1@testaccount1913.narod2.ru", accessToken, true)) | |
{ | |
client.Timeout = 400000; | |
client.SecurityMode = SmtpSslSecurityMode.Implicit; | |
client.EnableSsl = true; | |
client.Send(message); | |
} | |
} | |
static void AccessIMAPServer(string accessToken) | |
{ | |
using (ImapClient client = new ImapClient("imap.gmail.com", 993, "user1@testaccount1913.narod2.ru", accessToken, true)) | |
{ | |
client.EnableSsl = true; | |
client.SecurityMode = ImapSslSecurityMode.Implicit; | |
client.Connect(); | |
client.SelectFolder("Inbox"); | |
ImapMessageInfoCollection messageInfoCol = client.ListMessages(); | |
} | |
} | |
internal static string GetAccessToken(string authorizationCode) | |
{ | |
string actionUrl = "https://accounts.google.com/o/oauth2/token"; | |
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(actionUrl); | |
request.CookieContainer = new CookieContainer(); | |
request.Method = "POST"; | |
request.ContentType = "application/x-www-form-urlencoded"; | |
string encodedParameters = string.Format("client_id={1}&code={0}&client_secret={2}&redirect_uri={3}&grant_type={4}", | |
HttpUtility.UrlEncode(authorizationCode), | |
HttpUtility.UrlEncode("929645059575.apps.googleusercontent.com"), | |
HttpUtility.UrlEncode("USnH5eQRsC4XrjJbpGG7WVq5"), | |
HttpUtility.UrlEncode("urn:ietf:wg:oauth:2.0:oob"), | |
HttpUtility.UrlEncode("authorization_code")); | |
byte[] requestData = Encoding.UTF8.GetBytes(encodedParameters); | |
request.ContentLength = requestData.Length; | |
if (requestData.Length > 0) | |
using (Stream stream = request.GetRequestStream()) | |
stream.Write(requestData, 0, requestData.Length); | |
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); | |
string responseText = null; | |
using (TextReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) | |
responseText = reader.ReadToEnd(); | |
string accessToken = null; | |
foreach (string sPair in responseText.Replace("{", "").Replace("}", "").Replace("\"", ""). | |
Split(new string[] { ",\n" }, StringSplitOptions.None)) | |
{ | |
string[] pair = sPair.Split(':'); | |
if ("access_token" == pair[0].Trim()) | |
{ | |
accessToken = pair[1].Trim(); | |
break; | |
} | |
} | |
return accessToken; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance of the MailMessage class and Attachment class | |
MailMessage message = new MailMessage(); | |
message.From = "sender@sender.com"; | |
message.To.Add("receiver@receiver.com"); | |
// Adding 1st attachment, Create an instance of Attachment class, Load or add an attachment, Save the attachment then add the attachment to the message | |
Attachment attachment; | |
attachment = new Attachment(@"d:\1.txt"); | |
attachment.Save(@"e:\2.txt"); | |
message.Attachments.Add(attachment); | |
// Create an instance of the SmtpClient Class and Specify your mailing host server, Username, Password and Port | |
SmtpClient client = new SmtpClient(); | |
client.Host = "smtp.server.com"; | |
client.Username = "Username"; | |
client.Password = "Password"; | |
client.Port = 25; | |
try | |
{ | |
// Client.Send will send this message | |
client.Send(message); | |
Console.WriteLine("Message sent"); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Trace.WriteLine(ex.ToString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create a message and Subscribe to the Inbox folder ans Append the newly created message | |
MailMessage message = new MailMessage("user@domain1.com","user@domain2.com","subject","message"); | |
imap.SelectFolder(ImapFolderInfo.InBox); | |
imap.SubscribeFolder(imap.CurrentFolder.Name); | |
imap.AppendMessage(imap.CurrentFolder.Name, msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory and Instantiate an instance of MailPrinter | |
string dataDir = RunExamples.GetDataDir_Email(); | |
Printing.MailPrinter printer = new Printing.MailPrinter(); | |
printer.DpiX = 300; | |
printer.DpiY = 300; | |
MailMessage msg = MailMessage.Load(dataDir + "Message.msg", MessageFormat.Msg); | |
printer.Print(msg, dataDir + "AdjustTargetDPI_out.tiff", Printing.PrintFormat.Tiff); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
<configuration> | |
<configSections> | |
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | |
<section name="Aspose.Email.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> | |
</sectionGroup> | |
</configSections> | |
<applicationSettings> | |
<Aspose.Email.Properties.Settings> | |
<setting name="ImapDiagnosticLog" serializeAs="String"> | |
<value>Aspose.Email.IMAP.log</value> | |
</setting> | |
<setting name="ImapDiagnosticLog_UseDate" serializeAs="String"> | |
<value>True</value> | |
</setting> | |
</Aspose.Email.Properties.Settings> | |
</applicationSettings> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
<configuration> | |
<configSections> | |
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | |
<section name="Aspose.Email.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> | |
</sectionGroup> | |
</configSections> | |
<applicationSettings> | |
<Aspose.Email.Properties.Settings> | |
<setting name="Pop3DiagnosticLog" serializeAs="String"> | |
<value>Aspose.Email.Pop3.log</value> | |
</setting> | |
<setting name="Pop3DiagnosticLog_UseDate" serializeAs="String"> | |
<value>True</value> | |
</setting> | |
</Aspose.Email.Properties.Settings> | |
</applicationSettings> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
<configuration> | |
<configSections> | |
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > | |
<section name="Aspose.Email.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> | |
</sectionGroup> | |
</configSections> | |
<applicationSettings> | |
<Aspose.Email.Properties.Settings> | |
<setting name="SmtpDiagnosticLog" serializeAs="String"> | |
<value>Aspose.Email.SMTP.log</value> | |
</setting> | |
</Aspose.Email.Properties.Settings> | |
</applicationSettings> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage(); | |
// Specify From, To, Subject and Body | |
message.From = txtFrom.Text; | |
message.To = txtTo.Text; | |
message.Subject = "My First Mail"; | |
message.Body = txtBody.Text; | |
// Send email using SmtpClient, Create an instance of the SmtpClient Class and Specify the mailing host server, Username, Password and Port | |
SmtpClient client = new SmtpClient(); | |
// Specify the mailing host server, Username, Password and Port | |
client.Host = "mail.server.com"; | |
client.Username = "username"; | |
client.Password = "password"; | |
client.Port = 25; | |
client.Send(message); | |
// Notify the user that a message has been sent | |
MessageBox.Show("Message Sent"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Clear the items in the listbox | |
lstMessages.Items.Clear(); | |
// Create instance of ExchangeClient class by giving credentials and Call ListMessages method to list messages info from Inbox | |
ExchangeClient client = new ExchangeClient(txtExchangeServer.Text, txtUsername.Text, txtPassword.Text, txtDomain.Text); | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to display the basic information | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMsgInfo = "Subject: " + msgInfo.Subject + " == From: " + msgInfo.From.ToString() + " == To: " + msgInfo.To.ToString(); | |
lstMessages.Items.Add(strMsgInfo); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Creates an instance of the class ImapClient by specified the host, username and password | |
ImapClient client = new ImapClient("localhost", "username", "password"); | |
try | |
{ | |
client.SelectFolder(ImapFolderInfo.InBox); | |
String strTemp; | |
strTemp = "You have " + client.CurrentFolder.TotalMessageCount.ToString() + " messages in your account."; | |
// Gets number of messages in the folder, Disconnects to imap server. | |
MessageBox.Show(strTemp); | |
client.Disconnect(); | |
} | |
catch (ImapException ex) | |
{ | |
MessageBox.Show(ex.ToString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set security mode | |
client.SecurityOptions = SecurityOptions.SSLImplicit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create a POP3 client | |
Aspose.Email.Pop3.Pop3Client client; | |
client = new Aspose.Email.Pop3.Pop3Client(); | |
// Basic settings (required) | |
client.Host = "pop3.youdomain.com"; | |
client.Username = "username"; | |
client.Password = "psw"; | |
try | |
{ | |
// Retrieve first message in MailMessage format directly | |
Aspose.Email.Mail.MailMessage msg; | |
msg = client.FetchMessage(1); | |
txtFrom.Text = msg.From.ToString(); | |
txtSubject.Text = msg.Subject.ToString(); | |
txtBody.Text = msg.HtmlBody.ToString(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
try | |
{ | |
// Disconnect from POP3 server | |
client.Disconnect(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set implicit security mode | |
client.SecurityOptions = Aspose.Email.SecurityOptions.SSLImplicit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
RecurrencePattern recurrencePattern = new RecurrencePattern(); | |
recurrencePattern.StartDate = new DateTime(1997, 9, 10, 9, 0, 0); | |
RecurrenceRule rule = recurrencePattern.RRules.Add(); | |
rule.Frequency = Frequency.Monthly; | |
rule.Count = 20; | |
rule.Interval = 18; | |
rule.ByMonthDay.Add(new int[] { 10, 11, 12, 13, 14, 15 }); | |
DateCollection expectedDates = recurrencePattern.GenerateOccurrences(20); | |
Console.WriteLine("expectedDates.Count = " + expectedDates.Count); | |
foreach (DateTime date in expectedDates) | |
{ | |
Console.WriteLine("DateTime = " + date); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
try | |
{ | |
// Get the message ID of the selected row | |
string strMessageID = dgMeetings.SelectedRows[0].Cells["MessageID"].Value.ToString(); | |
// Get the message and calendar information from the database get the attendee information | |
string strSQLGetAttendees = "SELECT * FROM Attendent WHERE MessageID = '" + strMessageID + "' "; | |
// Get the attendee information in reader | |
SqlDataReader rdAttendees = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSQLGetAttendees, null); | |
// Create a MailAddressCollection from the attendees found in the database | |
MailAddressCollection attendees = new MailAddressCollection(); | |
while (rdAttendees.Read()) | |
{ | |
attendees.Add(new MailAddress(rdAttendees["EmailAddress"].ToString(), rdAttendees["DisplayName"].ToString())); | |
} | |
// Get message and calendar information | |
string strSQLGetMessage = "SELECT * FROM [Message] WHERE MessageID = '" + strMessageID + "' "; | |
// Get the reader for the above query | |
SqlDataReader rdMessage = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSQLGetMessage, null); | |
rdMessage.Read(); | |
// Create the Calendar object from the database information | |
Appointment app = new Appointment(rdMessage["CalLocation"].ToString(), rdMessage["CalSummary"].ToString(), rdMessage["CalDescription"].ToString(), | |
DateTime.Parse(rdMessage["CalStartTime"].ToString()), DateTime.Parse(rdMessage["CalEndTime"].ToString()), new MailAddress(rdMessage["FromEmailAddress"].ToString(), rdMessage["FromDisplayName"].ToString()), attendees); | |
// Create message and Set from and to addresses and Add the cancel meeting request | |
MailMessage msg = new MailMessage(); | |
msg.From = new MailAddress(rdMessage["FromEmailAddress"].ToString(), ""); | |
msg.To = attendees; | |
msg.Subject = "Cencel meeting"; | |
msg.AddAlternateView(app.CancelAppointment()); | |
SmtpClient smtp = new SmtpClient("mail.domain.com", "user", "password"); | |
smtp.Send(msg); | |
MessageBox.Show("cancellation request successfull"); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set conditions | |
ImapQueryBuilder builder = new ImapQueryBuilder(); | |
builder.Subject.Contains("Newsletter",true); | |
builder.InternalDate.On(DateTime.Now); | |
MailQuery query = builder.GetQuery(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage message = new MailMessage("Sender Name <sender@from.com>", "Kyle Huang <kyle@to.com>"); | |
// A To address with a friendly name can also be specified like this | |
// message.To.Add(new MailAddress("kyle@to.com", "Kyle Huang")); | |
// Specify Cc and Bcc email address along with a friendly name | |
message.CC.Add(new MailAddress("guangzhou@cc.com", "Guangzhou Team")); | |
message.Bcc.Add(new MailAddress("ahaq@bcc.com", "Ammad ulHaq ")); | |
// Create an instance of SmtpClient Class and Specify your mailing host server, Username, Password, Port | |
SmtpClient client = new SmtpClient(); | |
client.Host = "smtp.server.com"; | |
client.Username = "Username"; | |
client.Password = "Password"; | |
client.Port = 25; | |
try | |
{ | |
// Client.Send will send this message | |
client.Send(message); | |
Console.WriteLine("Message sent"); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Trace.WriteLine(ex.ToString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an object of type Pop3MailboxInfo and Get the mailbox information, Check number of messages, and Check mailbox size | |
Aspose.Email.Pop3.Pop3MailboxInfo info; | |
info = client.GetMailboxInfo(); | |
Console.WriteLine(info.MessageCount); | |
Console.Write(info.OccupiedSize + " bytes"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Get the list of messages in the mailbox and Iterate through the messages | |
Aspose.Email.Pop3.Pop3MessageInfoCollection infos = client.ListMessages(); | |
foreach (Aspose.Email.Pop3.Pop3MessageInfo info in infos) | |
{ | |
Console.Write("ID:" + info.UniqueId); | |
Console.Write("Index number:" + info.SequenceNumber); | |
Console.Write("Subject:" + info.Subject); | |
Console.Write("Size:" + info.Size); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Emails from specific host, get all emails that arrived before today and all emails that arrived since 7 days ago | |
builder.From.Contains("SpecificHost.com"); | |
builder.InternalDate.Before(DateTime.Now); | |
builder.InternalDate.Since(DateTime.Now.AddDays(-7)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Get emails sent to specific recipient | |
builder.To.Contains("recipient"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Specify OR condition | |
builder.Or(builder.Subject.Contains("test"), builder.From.Contains("noreply@host.com")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an imapclient with host, user and password | |
ImapClient client = new ImapClient("localhost", "user", "password"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
Aspose.Email.Mail.SmtpClient client = new SmtpClient("smtp.gmail.com"); | |
client.Username = "user@gmail.com"; | |
client.Password = "pwd"; | |
client.Port = 587; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
Aspose.Email.Imap.ImapClient client = new Aspose.Email.Imap.ImapClient("imap.domain.com", 993, "user@domain.com", "pwd"); | |
// Set the security mode to implicit | |
client.SecurityOptions = SecurityOptions.SSLImplicit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Connect to the Gmail server | |
Aspose.Email.Imap.ImapClient imap = new Aspose.Email.Imap.ImapClient("imap.gmail.com", 993, "user@gmail.com", "pwd"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory and load the MSG file using Aspose.Email for .NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MailMessage msg = MailMessage.Load(dataDir + "test-message.msg", new MsgLoadOptions()); | |
// Convert MSG to MHTML and save to stream | |
MemoryStream msgStream = new MemoryStream(); | |
msg.Save(msgStream, SaveOptions.DefaultMhtml); | |
msgStream.Position = 0; | |
// Load the MHTML stream using Aspose.Words for .NET and Save the document as TIFF image | |
Document msgDocument = new Document(msgStream); | |
msgDocument.Save(dataDir+ "Outlook-Aspose_out.tif", SaveFormat.Tiff); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
imap.CreateFolder("NewFolder"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Delete a folder and Rename a folder | |
imap.DeleteFolder("foldername"); | |
imap.RenameFolder("foldername", "newfoldername"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Connect to the POP3 mail server and check messages. | |
Aspose.Email.Pop3.Pop3Client pop3Client = new Aspose.Email.Pop3.Pop3Client("pop3mailserver", "username", "password"); | |
pop3Client.Connect(true); | |
// List all the messages | |
Aspose.Email.Pop3.Pop3MessageInfoCollection msgList = pop3Client.ListMessages(); | |
foreach (Aspose.Email.Pop3.Pop3MessageInfo msgInfo in msgList) | |
{ | |
// Get the POP3 message's unique ID | |
string strUniqueID = msgInfo.UniqueId; | |
// Search your local database or data store on the unique ID. If a match is found, that means it's already downloaded. Otherwise download and save it. | |
if (SearchPop3MsgInLocalDB(strUniqueID) == true) | |
{ | |
// The message is already in the database. Nothing to do with this message. Go to next message. | |
} | |
else | |
{ | |
// Save the message | |
SavePop3MsgInLocalDB(msgInfo); | |
} | |
} | |
private void SavePop3MsgInLocalDB(Aspose.Email.Pop3.Pop3MessageInfo msgInfo) | |
{ | |
// Open the database connection according to your database. Use public properties (for example msgInfo.Subject) and store in database, | |
// for example, " INSERT INTO POP3Mails (UniqueID, Subject) VALUES ('" + msgInfo.UniqueID + "' , '" + msgInfo.Subject + "') and Run the query to store in database. | |
} | |
private bool SearchPop3MsgInLocalDB(string strUniqueID) | |
{ | |
// Open the database connection according to your database. Use strUniqueID in the search query to find existing records, | |
// for example, " SELECT COUNT(*) FROM POP3Mails WHERE UniqueID = '" + strUniqueID + "' Run the query, return true if count == 1. Return false if count == 0. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
//Create a loop to display the no. of attachments present in email message | |
foreach (Attachment attachment in message.Attachments) | |
{ | |
// Save your attachments here and display the the attachment file name | |
attachment.Save("filename"); | |
Console.WriteLine(attachment.Name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Export an EML file | |
msg.Save(@"e:\test.eml", SaveOptions.DefaultEml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Create an instance of MailMessage class | |
MailMessage message = new MailMessage { From = "sender@sender.com" }; | |
message.To.Add("receiver@gmail.com"); | |
// Load an attachment | |
Attachment attachment = new Attachment(dataDir + "1.txt"); | |
// Add Multiple Attachment in instance of MailMessage class and Save message to disk | |
message.Attachments.Add(attachment); | |
message.AddAttachment(new Attachment(dataDir + "1.jpg")); | |
message.AddAttachment(new Attachment(dataDir + "1.doc")); | |
message.AddAttachment(new Attachment(dataDir + "1.rar")); | |
message.AddAttachment(new Attachment(dataDir + "1.pdf")); | |
message.Save(dataDir + "outputAttachments_out.msg", SaveOptions.DefaultMsgUnicode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Create an instance of MailMessage class | |
MailMessage message = new MailMessage {From = "sender@sender.com"}; | |
message.To.Add("receiver@gmail.com"); | |
// Load an attachment | |
Attachment attachment = new Attachment(dataDir + "1.txt"); | |
// Add Multiple Attachment in instance of MailMessage class and Save message to disk | |
message.Attachments.Add(attachment); | |
message.AddAttachment(new Attachment(dataDir + "1.jpg")); | |
message.AddAttachment(new Attachment(dataDir + "1.doc")); | |
message.AddAttachment(new Attachment(dataDir + "1.rar")); | |
message.AddAttachment(new Attachment(dataDir + "1.pdf")); | |
message.Save(dataDir + "outputAttachments_out.msg", SaveOptions.DefaultMsgUnicode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string fileName = "MainMessage.eml"; | |
string attachName = "s.png"; | |
string outFileName = "test.eml"; | |
MailMessage mailMessage = MailMessage.Load(fileName); | |
mailMessage.Attachments.Add(new Attachment(File.OpenRead(attachName), "s.png", "image/png")); | |
mailMessage.Save(outFileName, FileCompatibilityMode.PreserveTnefAttachments); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string fileName = "tnefEml1.eml"; | |
string attachName = "Untitled.jpg"; | |
string outFileName = "test_out.eml"; | |
MailMessage mailMessage = MailMessage.Load(dataDir + fileName); | |
mailMessage.Attachments.Add(new Attachment(File.OpenRead(dataDir + attachName), "Untitled.jpg", "image/jpg")); | |
EmlSaveOptions eo = new EmlSaveOptions(MailMessageSaveType.EmlFormat); | |
eo.FileCompatibilityMode = FileCompatibilityMode.PreserveTnefAttachments; | |
mailMessage.Save(dataDir + outFileName, eo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
AlternateView alternate; | |
// Creates AlternateView to view an email message using the content specified in the //string | |
alternate = AlternateView.CreateAlternateViewFromString("Alternate Text"); | |
// Adding alternate text | |
message.AlternateViews.Add(alternate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance of SmtpClient class | |
SmtpClient client = new SmtpClient(); | |
client.AuthenticationMethod = SmtpAuthentication.Auto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string hamFolder = RunExamples.GetDataDir_Email() + "/hamFolder"; | |
string spamFolder = RunExamples.GetDataDir_Email() + "/Spam"; | |
string testFolder = RunExamples.GetDataDir_Email(); | |
string dataBaseFile = RunExamples.GetDataDir_Email() + "SpamFilterDatabase.txt"; | |
TeachAndCreateDatabase(hamFolder, spamFolder, dataBaseFile); | |
string[] testFiles = Directory.GetFiles(testFolder, "*.eml"); | |
SpamAnalyzer analyzer = new SpamAnalyzer(dataBaseFile); | |
foreach (string file in testFiles) | |
{ | |
MailMessage msg = MailMessage.Load(file); | |
Console.WriteLine(msg.Subject); | |
double probability = analyzer.Test(msg); | |
PrintResult(probability); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string hamFolder = RunExamples.GetDataDir_Email() + "/hamFolder"; | |
string spamFolder = RunExamples.GetDataDir_Email() + "/Spam"; | |
string testFolder = RunExamples.GetDataDir_Email(); | |
string dataBaseFile = RunExamples.GetDataDir_Email() + "SpamFilterDatabase.txt"; | |
TeachAndCreateDatabase(hamFolder, spamFolder, dataBaseFile); | |
string[] testFiles = Directory.GetFiles(testFolder, "*.eml"); | |
SpamAnalyzer analyzer = new SpamAnalyzer(dataBaseFile); | |
foreach (string file in testFiles) | |
{ | |
MailMessage msg = MailMessage.Load(file); | |
Console.WriteLine(msg.Subject); | |
double probability = analyzer.Test(msg); | |
PrintResult(probability); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.BodyEncoding = Encoding.ASCII; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MailMessage message = MailMessage.Load(dataDir + "test.eml"); | |
// A To address with a friendly name can also be specified like this | |
message.To.Add(new MailAddress("kyle@to.com", "Kyle Huang")); | |
// Specify Cc and Bcc email address along with a friendly name | |
message.CC.Add(new MailAddress("guangzhou@cc.com", "Guangzhou Team")); | |
message.Bcc.Add(new MailAddress("ahaq@bcc.com", "Ammad ulHaq ")); | |
message.Save(dataDir + "MessageWithFrienlyName_out.eml", SaveOptions.DefaultEml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MailMessage eml = MailMessage.Load(dataDir + "Message.eml"); | |
MhtSaveOptions options = SaveOptions.DefaultMhtml; | |
int cssInsertPos = options.CssStyles.LastIndexOf("</style>"); | |
options.CssStyles = options.CssStyles.Insert(cssInsertPos, | |
".PlainText{" + | |
" font-family: sans-serif;" + | |
"}" | |
); | |
eml.Save("message.mhtml", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string fileName = RunExamples.GetDataDir_Email() + "failed1.msg"; | |
MailMessage mail = MailMessage.Load(fileName); | |
BounceResult result = mail.CheckBounced(); | |
Console.WriteLine(fileName); | |
Console.WriteLine("IsBounced : " + result.IsBounced); | |
Console.WriteLine("Action : " + result.Action); | |
Console.WriteLine("Recipient : " + result.Recipient); | |
Console.WriteLine(); | |
Console.WriteLine("Reason : " + result.Reason); | |
Console.WriteLine("Status : " + result.Status); | |
Console.WriteLine("OriginalMessage ToAddress 1: " + result.OriginalMessage.To[0].Address); | |
Console.WriteLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage mailMessageOrig = MailMessage.Load(Path.Combine(dataDir, "Message.msg"), new MsgLoadOptions()); | |
X509Certificate2 publicCert = new X509Certificate2(publicCertFile); | |
X509Certificate2 privateCert = new X509Certificate2(privateCertFile, "anothertestaccount"); | |
Console.WriteLine("Message is encrypted: {0}" , mailMessageOrig.IsEncrypted); | |
MailMessage mailMessage = mailMessageOrig.Encrypt(publicCert); | |
Console.WriteLine("Message is encrypted: {0}", mailMessage.IsEncrypted); | |
mailMessage = mailMessage.Decrypt(privateCert); | |
Console.WriteLine("Message is encrypted: {0}", mailMessage.IsEncrypted); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.ConfirmRead = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage eml = MailMessage.Load(Path.Combine(dataDir, "Message.eml")); | |
// Save as mht with header | |
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions | |
{ | |
//Specify formatting options required | |
//Here we are specifying to write header informations to outpu without writing extra print header | |
//and the output headers should display as the original headers in message | |
MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.DisplayAsOutlook, | |
// Check the body encoding for validity. | |
CheckBodyContentEncoding = true | |
}; | |
eml.Save(Path.Combine(dataDir, "outMessage_out.mht"), mhtSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
mhtSaveOptions.SkipInlineImages = true; | |
eml.Save(Path.Combine(dataDir, "EmlToMhtmlWithoutInlineImages_out.mht"), mhtSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https:// github.com/aspose-email/Aspose.Email-for-.NET | |
string username = "username"; | |
string email = "email@gmail.com"; | |
string password = "password"; | |
string clientId = "clientid"; | |
string clientSecret = "client secret"; | |
string refresh_token = "refresh token"; | |
// The refresh_token is to be used in below. | |
GoogleTestUser user = new GoogleTestUser(username, email, password, clientId, clientSecret, refresh_token); | |
using (IGmailClient client = Aspose.Email.Google.GmailClient.GetInstance(user.ClientId, user.ClientSecret, user.RefreshToken)) | |
{ | |
Contact[] contacts = client.GetAllContacts(); | |
foreach (Contact contact in contacts) | |
Console.WriteLine(contact.DisplayName + ", " + contact.EmailAddresses[0]); | |
// Fetch contacts from a specific group | |
FeedEntryCollection groups = client.FetchAllGroups(); | |
GmailContactGroup group = null; | |
foreach (GmailContactGroup g in groups) | |
switch (g.Title) | |
{ | |
case "TestGroup": group = g; | |
break; | |
} | |
// Retrieve contacts from the Group | |
if (group != null) | |
{ | |
Contact[] contacts2 = client.GetContactsFromGroup(group); | |
foreach (Contact con in contacts2) | |
Console.WriteLine(con.DisplayName + "," + con.EmailAddresses[0].ToString()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Create a new instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Set subject of the message, Html body and sender information | |
message.Subject = "New message created by Aspose.Email for .NET"; | |
message.HtmlBody = "<b>This line is in bold.</b> <br/> <br/>" + "<font color=blue>This line is in blue color</font>"; | |
message.From = new MailAddress("from@domain.com", "Sender Name", false); | |
// Add TO recipients and Add CC recipients | |
message.To.Add(new MailAddress("to1@domain.com", "Recipient 1", false)); | |
message.To.Add(new MailAddress("to2@domain.com", "Recipient 2", false)); | |
message.CC.Add(new MailAddress("cc1@domain.com", "Recipient 3", false)); | |
message.CC.Add(new MailAddress("cc2@domain.com", "Recipient 4", false)); | |
// Save message in EML, EMLX, MSG and MHTML formats | |
message.Save(dataDir + "CreateNewMailMessage_out.eml", SaveOptions.DefaultEml); | |
message.Save(dataDir + "CreateNewMailMessage_out.emlx", SaveOptions.CreateSaveOptions(MailMessageSaveType.EmlxFormat)); | |
message.Save(dataDir + "CreateNewMailMessage_out.msg", SaveOptions.DefaultMsgUnicode); | |
message.Save(dataDir + "CreateNewMailMessage_out.mhtml", SaveOptions.DefaultMhtml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessageLoadOptions options = new MailMessageLoadOptions(); | |
options.MessageFormat = MessageFormat.Msg; | |
// The PreserveTnefAttachments option with MessageFormat.Msg will create the TNEF eml. | |
options.FileCompatibilityMode = FileCompatibilityMode.PreserveTnefAttachments; | |
MailMessage eml = MailMessage.Load(emlFileName, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MapiMessage mapiMsg = MapiMessage.FromFile(dataDir + "Message.msg"); | |
MailConversionOptions mco = new MailConversionOptions(); | |
mco.ConvertAsTnef = true; | |
MailMessage message = mapiMsg.ToMailMessage(mco); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https:// github.com/aspose-email/Aspose.Email-for-.NET | |
string username = "newcustomeroffnet"; | |
string email = "newcustomeroffnet@gmail.com"; | |
string password = "visual2010"; | |
string clientId = "633643385868-v64nsvkmh5ca2dlhkroo8941ne92onov.apps.googleusercontent.com"; | |
string clientSecret = "UQ26EXvvo8L12TNhtLtYbHVO"; | |
string refresh_token = "1/yord7s4aqV8t7S_vT9IqlBO60eIE-hY0WHLfqQ9zOCQ"; | |
// The refresh_token is to be used in below. | |
GoogleTestUser user = new GoogleTestUser(username, email, password, clientId, clientSecret,refresh_token); | |
// Gmail Client | |
IGmailClient client = Aspose.Email.Google.GmailClient.GetInstance(user.ClientId, user.ClientSecret, user.RefreshToken, user.EMail); | |
// Create a Contact | |
Contact contact = new Contact(); | |
contact.Prefix = "Prefix"; | |
contact.GivenName = "GivenName"; | |
contact.Surname = "Surname"; | |
contact.MiddleName = "MiddleName"; | |
contact.DisplayName = "Test User 1"; | |
contact.Suffix = "Suffix"; | |
contact.JobTitle = "JobTitle"; | |
contact.DepartmentName = "DepartmentName"; | |
contact.CompanyName = "CompanyName"; | |
contact.Profession = "Profession"; | |
contact.Notes = "Notes"; | |
PostalAddress address = new PostalAddress(); | |
address.Category = PostalAddressCategory.Work; | |
address.Address = "Address"; | |
address.Street = "Street"; | |
address.PostOfficeBox = "PostOfficeBox"; | |
address.City = "City"; | |
address.StateOrProvince = "StateOrProvince"; | |
address.PostalCode = "PostalCode"; | |
address.Country = "Country"; | |
contact.PhysicalAddresses.Add(address); | |
PhoneNumber pnWork = new PhoneNumber(); | |
pnWork.Number = "323423423423"; | |
pnWork.Category = PhoneNumberCategory.Work; | |
contact.PhoneNumbers.Add(pnWork); | |
PhoneNumber pnHome = new PhoneNumber(); | |
pnHome.Number = "323423423423"; | |
pnHome.Category = PhoneNumberCategory.Home; | |
contact.PhoneNumbers.Add(pnHome); | |
PhoneNumber pnMobile = new PhoneNumber(); | |
pnMobile.Number = "323423423423"; | |
pnMobile.Category = PhoneNumberCategory.Mobile; | |
contact.PhoneNumbers.Add(pnMobile); | |
contact.Urls.Blog = "Blog.ru"; | |
contact.Urls.BusinessHomePage = "BusinessHomePage.ru"; | |
contact.Urls.HomePage = "HomePage.ru"; | |
contact.Urls.Profile = "Profile.ru"; | |
contact.Events.Birthday = DateTime.Now.AddYears(-30); | |
contact.Events.Anniversary = DateTime.Now.AddYears(-10); | |
contact.InstantMessengers.AIM = "AIM"; | |
contact.InstantMessengers.GoogleTalk = "GoogleTalk"; | |
contact.InstantMessengers.ICQ = "ICQ"; | |
contact.InstantMessengers.Jabber = "Jabber"; | |
contact.InstantMessengers.MSN = "MSN"; | |
contact.InstantMessengers.QQ = "QQ"; | |
contact.InstantMessengers.Skype = "Skype"; | |
contact.InstantMessengers.Yahoo = "Yahoo"; | |
contact.AssociatedPersons.Spouse = "Spouse"; | |
contact.AssociatedPersons.Sister = "Sister"; | |
contact.AssociatedPersons.Relative = "Relative"; | |
contact.AssociatedPersons.ReferredBy = "ReferredBy"; | |
contact.AssociatedPersons.Partner = "Partner"; | |
contact.AssociatedPersons.Parent = "Parent"; | |
contact.AssociatedPersons.Mother = "Mother"; | |
contact.AssociatedPersons.Manager = "Manager"; | |
// Email Address | |
EmailAddress eAddress = new EmailAddress(); | |
eAddress.Address = "email@gmail.com"; | |
contact.EmailAddresses.Add(eAddress); | |
string contactUri = client.CreateContact(contact); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MapiMessage msg = MapiMessage.FromFile(dataDir + "Message.msg"); | |
MailConversionOptions options = new MailConversionOptions {ConvertAsTnef = true}; | |
MailMessage mail = msg.ToMailMessage(options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance MailMessage class | |
MailMessage mailMessage = new MailMessage(); | |
// Specify ReplyTo, From, To field, Cc and Bcc Addresses | |
mailMessage.ReplyToList.Add("reply@reply.com"); | |
mailMessage.From = "sender@sender.com"; | |
mailMessage.To.Add("receiver1@receiver.com"); | |
mailMessage.CC.Add("receiver2@receiver.com"); | |
mailMessage.Bcc.Add("receiver3@receiver.com"); | |
// Specify Date, Message subject, XMailer, Secret Header, Save message to disc | |
mailMessage.Subject = "test mail"; | |
mailMessage.Date = new System.DateTime(2006, 3, 6); | |
mailMessage.XMailer = "Aspose.Email"; | |
mailMessage.Headers.Add_("secret-header", "mystery"); | |
mailMessage.Save("MessageHeaders.msg", SaveOptions.DefaultMsg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Add by SMTP server in delivery emails | |
Received: from ip-123.56.99.216.dsl-cust.ca.inter.net ([216.99.56.123]) by Aspose.secureserver.net with MailEnable ESMTP; Thu, 22 Feb 2007 13:58:57 -0700 | |
// Add by SMTP server in delivery emails | |
Return-Path: <xyz@oikoscucine.it> | |
// Add by SMTP server in delivery emails | |
Received: from 195.120.225.20 (HELO mail.oikoscucine.it) | |
by aspose.com with esmtp (:1CYY+<LA*- *1WK@) | |
id Q8,/O/-.N83@7-9M | |
for abc@aspose.com; Thu, 22 Feb 2007 20:58:51 +0300 | |
From: "XYZ" <xyz@oikoscucine.it> | |
To: <abc@aspose.com> | |
Subject: For ABC | |
// Date will set the Date field, outlook will show this as | |
Date: Thu, 22 Feb 2007 20:58:51 +0300 | |
Message-ID: <01c756c4$41b554d0$6c822ecf@dishonestyinsufferably> | |
MIME-Version: 1.0 | |
Content-Type: multipart/alternative; | |
boundary="----=_NextPart_000_0006_01C7569A.58DF4CD0" | |
X-Mailer: Microsoft Office Outlook, Build 11.0.5510 | |
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 | |
Thread-Index: Aca6Q:=ES0M(9-=(<.<1.<Q9@QE6CD== | |
X-Read: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
client.DeliveryMethod = SmtpDeliveryMethod.Network; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Detect file format and Gets the detected load format | |
FileFormatInfo info = FileFormatUtil.DetectFileFormat(dataDir + "message.msg"); | |
Console.WriteLine("The message format is: " + info.FileFormatType); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage mail = MailMessage.Load(dataDir + "tnefEml1.eml"); | |
bool isTnef = mail.OriginalIsTnef; | |
Console.WriteLine("Is input EML originally TNEF? {0}", isTnef.ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email() + "Message.eml"; | |
MailMessage mail = MailMessage.Load(dataDir); | |
bool isTnef = mail.OriginalIsTnef; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email() + "EmailWithAttandEmbedded.eml"; | |
MailMessage eml = MailMessage.Load(dataDir); | |
if (eml.Attachments[0].IsEmbeddedMessage) | |
Console.WriteLine("Attachment is an embedded message."); | |
else | |
Console.WriteLine("Attachment is not an embedded message."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create a loop to display the no. of attachments present in email message | |
foreach (Attachment attachment in message.Attachments) | |
{ | |
// Display the the attachment file name | |
Console.WriteLine(attachment.Name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage("Sender <sender@from.com>", "Recipient <recipient@to.com>"); | |
// Specify the recipients mail addresses | |
message.To.Add("receiver1@receiver.com"); | |
message.To.Add("receiver2@receiver.com"); | |
message.To.Add("receiver3@receiver.com"); | |
message.To.Add("receiver4@receiver.com"); | |
// Specifying CC and BCC Addresses | |
message.CC.Add("CC1@receiver.com"); | |
message.CC.Add("CC2@receiver.com"); | |
message.Bcc.Add("Bcc1@receiver.com"); | |
message.Bcc.Add("Bcc2@receiver.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Create MailMessage instance by loading an Eml file | |
MailMessage message = MailMessage.Load(dataDir + "test.eml", new EmlLoadOptions()); | |
// Gets the sender info, recipient info, Subject, htmlbody and textbody | |
Console.Write("From:"); | |
Console.WriteLine(message.From); | |
Console.Write("To:"); | |
Console.WriteLine(message.To); | |
Console.Write("Subject:"); | |
Console.WriteLine(message.Subject); | |
Console.WriteLine("HtmlBody:"); | |
Console.WriteLine(message.HtmlBody); | |
Console.WriteLine("TextBody"); | |
Console.WriteLine(message.Body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage message = new MailMessage("Sender <sender@from.com>", "Recipient <recipient@to.com>"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
string ical = @"BEGIN:VCALENDAR | |
METHOD:PUBLISH | |
PRODID:-//Aspose Ltd//iCalender Builder (v3.0)//EN | |
VERSION:2.0 | |
BEGIN:VEVENT | |
ATTENDEE;CN=test@gmail.com:mailto:test@gmail.com | |
DTSTART:20130220T171439 | |
DTEND:20130220T174439 | |
DTSTAMP:20130220T161439Z | |
END:VEVENT | |
END:VCALENDAR"; | |
string sender = "test@gmail.com"; | |
string recipient = "test@email.com"; | |
MailMessage message = new MailMessage(sender, recipient, string.Empty, string.Empty); | |
AlternateView av = AlternateView.CreateAlternateViewFromString(ical, new ContentType("text/calendar")); | |
message.AlternateViews.Add(av); | |
MapiMessage msg = MapiMessage.FromMailMessage(message); | |
msg.Save(dataDir + "draft_out.msg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
string dstDraft = dataDir + "appointment-draft_out.msg"; | |
string sender = "test@gmail.com"; | |
string recipient = "test@email.com"; | |
MailMessage message = new MailMessage(sender, recipient, string.Empty, string.Empty); | |
Appointment app = new Appointment(string.Empty, DateTime.Now, DateTime.Now, sender, recipient) | |
{ | |
MethodType = AppointmentMethodType.Publish | |
}; | |
message.AddAlternateView(app.RequestApointment()); | |
MapiMessage msg = MapiMessage.FromMailMessage(message); | |
// Save the appointment as draft. | |
msg.Save(dstDraft); | |
Console.WriteLine(Environment.NewLine + "Draft saved at " + dstDraft); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
EmailValidator ev = new EmailValidator(); | |
ValidationResult result; | |
try | |
{ | |
ev.Validate(txtEmailAddr.Text, out result); | |
if (result.ReturnCode == ValidationResponseCode.ValidationSuccess) | |
{ | |
lblResult.Text = "The email address is valid."; | |
} | |
else | |
{ | |
lblResult.Text = "The mail address is invalid,return code is : " + result.ReturnCode + "."; | |
} | |
} | |
catch (Exception ex) | |
{ | |
lblResult.Text += "<br>" + ex.Message; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
string dstEmail = dataDir + "EmbeddedImage.msg"; | |
// Create an instance of the MailMessage class and Set the addresses and Set the content | |
MailMessage mail = new MailMessage(); | |
mail.From = new MailAddress("test001@gmail.com"); | |
mail.To.Add("test001@gmail.com"); | |
mail.Subject = "This is an email"; | |
// Create the plain text part It is viewable by those clients that don't support HTML | |
AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content", null, "text/plain"); | |
/* Create the HTML part.To embed images, we need to use the prefix 'cid' in the img src value. | |
The cid value will map to the Content-Id of a Linked resource. Thus <img src='cid:barcode'> will map to a LinkedResource with a ContentId of //'barcode'. */ | |
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:barcode>", null, "text/html"); | |
// Create the LinkedResource (embedded image) and Add the LinkedResource to the appropriate view | |
LinkedResource barcode = new LinkedResource(dataDir + "1.jpg", MediaTypeNames.Image.Jpeg) | |
{ | |
ContentId = "barcode" | |
}; | |
mail.LinkedResources.Add(barcode); | |
mail.AlternateViews.Add(plainView); | |
mail.AlternateViews.Add(htmlView); | |
mail.Save(dataDir + "EmbeddedImage_out.msg", SaveOptions.DefaultMsgUnicode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
string publicCertFile = dataDir + "MartinCertificate.cer"; | |
string privateCertFile = dataDir + "MartinCertificate.pfx"; | |
X509Certificate2 publicCert = new X509Certificate2(publicCertFile); | |
X509Certificate2 privateCert = new X509Certificate2(privateCertFile, "anothertestaccount"); | |
// Create a message | |
MailMessage msg = new MailMessage("atneostthaecrcount@gmail.com", "atneostthaecrcount@gmail.com", "Test subject", "Test Body"); | |
// Encrypt the message | |
MailMessage eMsg = msg.Encrypt(publicCert); | |
if (eMsg.IsEncrypted == true) | |
Console.WriteLine("Its encrypted"); | |
else | |
Console.WriteLine("Its NOT encrypted"); | |
// Decrypt the message | |
MailMessage dMsg = eMsg.Decrypt(privateCert); | |
if (dMsg.IsEncrypted == true) | |
Console.WriteLine("Its encrypted"); | |
else | |
Console.WriteLine("Its NOT encrypted"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MailMessage msg = MailMessage.Load(dataDir + "Message.eml"); | |
msg.Save(dataDir + "ExporttoEml_out.eml", SaveOptions.DefaultEml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage eml = MailMessage.Load(dataDir + "Message.eml"); | |
// Set the local time for message date. | |
eml.TimeZoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); | |
// or set custom time zone offset for message date (-0800) | |
// eml.TimeZoneOffset = new TimeSpan(-8,0,0); | |
// The dates will be rendered by local system time zone. | |
MhtSaveOptions so = new MhtSaveOptions(); | |
so.MhtFormatOptions = MhtFormatOptions.WriteHeader; | |
eml.Save(dataDir + "ExportEmailToMHTWithCustomTimezone_out.mhtml", so); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https:// github.com/aspose-email/Aspose.Email-for-.NET | |
// Export an EML file | |
message.Save(@"e:\test.eml", SaveOptions.DefaultEml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https:// github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage eml = MailMessage.Load(fileName); | |
// Set the local time for message date. | |
eml.TimeZoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); | |
// or set custom time zone offset for message date (-0800) | |
// eml.TimeZoneOffset = new TimeSpan(-8,0,0); | |
// The dates will be rendered by local system time zone. | |
eml.Save(outFileName, MessageFormat.Mht, MailMessageSaveOptions.WriteHeaderToMht); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage eml = MailMessage.Load(fileName); | |
// Set the local time for message date. | |
eml.TimeZoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); | |
// The dates will be rendered by local system time zone. | |
eml.Save(outFileName, MessageFormat.Mht, MailMessageSaveOptions.WriteHeaderToMht); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Create an instance of MailMessage and load an email file | |
MailMessage mailMsg = MailMessage.Load(dataDir + "EmailWithAttandEmbedded.eml"); | |
// Extract Attachments from the message | |
foreach (Attachment attachment in mailMsg.Attachments) | |
{ | |
// To display the the attachment file name | |
Console.WriteLine(attachment.Name); | |
// Save the attachment to disc | |
attachment.Save(dataDir + attachment.Name); | |
// You can also save the attachment to memory stream | |
MemoryStream ms = new MemoryStream(); | |
attachment.Save(ms); | |
} | |
// Extract Inline images from the message | |
foreach (LinkedResource lr in mailMsg.LinkedResources) | |
{ | |
Console.WriteLine(lr.ContentType.Name); | |
lr.Save(dataDir + lr.ContentType.Name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Create an instance of MailMessage and load an email file | |
MailMessage mailMsg = MailMessage.Load(dataDir + "Message.msg", new MsgLoadOptions()); | |
foreach (Attachment attachment in mailMsg.Attachments) | |
{ | |
// To display the the attachment file name | |
attachment.Save(dataDir + "MessageEmbedded_out.msg"); | |
Console.WriteLine(attachment.Name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create MailMessage instance by loading an EML file | |
MailMessage mailMessage = MailMessage.Load("Sample.eml", MailMessageLoadOptions.DefaultEml); | |
Console.WriteLine("\n\nheaders:\n\n"); | |
// Print out all the headers | |
foreach (String header in message.Headers) | |
{ | |
Console.WriteLine(header); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage message; | |
// Create MailMessage instance by loading an EML file | |
message = MailMessage.Load(dataDir + "email-headers.eml", new EmlLoadOptions()); | |
Console.WriteLine("\n\nheaders:\n\n"); | |
// Print out all the headers | |
int index = 0; | |
foreach (String header in message.Headers) | |
{ | |
Console.Write(header + " - "); | |
Console.WriteLine(message.Headers.Get(index++)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public static void ExtractInlineAttachments(string dataDir) | |
{ | |
MapiMessage message = MapiMessage.FromFile(dataDir + "MSG file with RTF Formatting.msg"); | |
MapiAttachmentCollection attachments = message.Attachments; | |
foreach (MapiAttachment attachment in attachments) | |
{ | |
if(IsAttachmentInline(attachment)) | |
{ | |
try | |
{ | |
SaveAttachment(attachment, new Guid().ToString()); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
} | |
} | |
static bool IsAttachmentInline(MapiAttachment attachment) | |
{ | |
foreach (MapiProperty property in attachment.ObjectData.Properties.Values) | |
{ | |
if (property.Name == "\x0003ObjInfo") | |
{ | |
ushort odtPersist1 = BitConverter.ToUInt16(property.Data, 0); | |
return (odtPersist1 & (1 << (7 - 1))) == 0; | |
} | |
} | |
return false; | |
} | |
static void SaveAttachment(MapiAttachment attachment, string fileName) | |
{ | |
foreach (MapiProperty property in attachment.ObjectData.Properties.Values) | |
{ | |
if (property.Name == "Package") | |
{ | |
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) | |
{ | |
fs.Write(property.Data, 0, property.Data.Length); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
string mhtFileName = dataDir + "Message.mhtml"; | |
MailMessage message = MailMessage.Load(dataDir + "Message.eml"); | |
string encodedPageHeader = @"<div><div class=3D'page=Header'>"Panditharatne, Mithra" <mithra=2Epanditharatne@cibc==2Ecom><hr/></div>"; | |
MhtMessageFormatter mailFormatter = new MhtMessageFormatter(); | |
MhtFormatOptions options = MhtFormatOptions.WriteCompleteEmailAddress | MhtFormatOptions.WriteHeader; | |
mailFormatter.Format(message); | |
message.Save(mhtFileName, Aspose.Email.Mail.SaveOptions.DefaultMhtml); | |
if (File.ReadAllText(mhtFileName).Contains(encodedPageHeader)) | |
{ | |
Console.WriteLine("True"); | |
} | |
else | |
{ | |
Console.WriteLine("False"); | |
} | |
//Assert.True(File.ReadAllText(mhtFileName).Contains(encodedPageHeader)); | |
options = options | MhtFormatOptions.HideExtraPrintHeader; | |
mailFormatter.Format(message); | |
message.Save(mhtFileName, Aspose.Email.Mail.SaveOptions.DefaultMhtml); | |
if (File.ReadAllText(mhtFileName).Contains(encodedPageHeader)) | |
{ | |
Console.WriteLine("True"); | |
} | |
else | |
{ | |
Console.WriteLine("False"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.Date = DateTime.Now; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage mailMessage = MailMessage.Load(dataDir + "emlWithHeaders.eml"); | |
string decodedValue = mailMessage.Headers.GetDecodedValue("Thread-Topic"); | |
Console.WriteLine(decodedValue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage mailMessage = MailMessage.Load("mail-8820003991514049235.EML"); | |
string decodedValue = mailMessage.Headers.GetDecodedValue("Thread-Topic"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string fileName = RunExamples.GetDataDir_Email() + "failed1.msg"; | |
MailMessage mail = MailMessage.Load(fileName); | |
BounceResult result = mail.CheckBounced(); | |
Console.WriteLine(fileName); | |
Console.WriteLine("IsBounced : " + result.IsBounced); | |
Console.WriteLine("Action : " + result.Action); | |
Console.WriteLine("Recipient : " + result.Recipient); | |
Console.WriteLine(); | |
Console.WriteLine("Reason : " + result.Reason); | |
Console.WriteLine("Status : " + result.Status); | |
Console.WriteLine("OriginalMessage ToAddress 1: " + result.OriginalMessage.To[0].Address); | |
Console.WriteLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public static void Run() | |
{ | |
string dataDir = RunExamples.GetDataDir_Email(); | |
var message = MapiMessage.FromFile(dataDir + "RemoveAttachments.msg"); | |
var attachments = message.Attachments; | |
var count = attachments.Count; | |
Console.WriteLine("Total attachments " + count); | |
for (int i = 0; i < attachments.Count; i++) | |
{ | |
var attachment = attachments[i]; | |
if (IsInlineAttachment(attachment, message)) | |
{ | |
Console.WriteLine(attachment.LongFileName + " is inline attachment"); | |
} | |
else | |
{ | |
Console.WriteLine(attachment.LongFileName + " is regular attachment"); | |
} | |
} | |
} | |
public static bool IsInlineAttachment(MapiAttachment att, MapiMessage msg) | |
{ | |
switch (msg.BodyType) | |
{ | |
case BodyContentType.PlainText: | |
// ignore indications for plain text messages | |
return false; | |
case BodyContentType.Html: | |
// check the PidTagAttachFlags property | |
if (att.Properties.ContainsKey(0x37140003)) | |
{ | |
long? attachFlagsValue = att.GetPropertyLong(0x37140003); | |
if (attachFlagsValue != null && (attachFlagsValue & 0x00000004) == 0x00000004) | |
{ | |
// check PidTagAttachContentId property | |
if (att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID) || | |
att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W)) | |
{ | |
string contentId = att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID) | |
? att.Properties[MapiPropertyTag.PR_ATTACH_CONTENT_ID].GetString() | |
: att.Properties[MapiPropertyTag.PR_ATTACH_CONTENT_ID_W].GetString(); | |
if (msg.BodyHtml.Contains(contentId)) | |
{ | |
return true; | |
} | |
} | |
// check PidTagAttachContentLocation property | |
if (att.Properties.ContainsKey(0x3713001E) || | |
att.Properties.ContainsKey(0x3713001F)) | |
{ | |
return true; | |
} | |
} | |
else if ((att.Properties.ContainsKey(0x3716001F) && att.GetPropertyString(0x3716001F) == "inline") | |
|| (att.Properties.ContainsKey(0x3716001E) && att.GetPropertyString(0x3716001E) == "inline")) | |
{ | |
return true; | |
} | |
} | |
else if ((att.Properties.ContainsKey(0x3716001F) && att.GetPropertyString(0x3716001F) == "inline") | |
|| (att.Properties.ContainsKey(0x3716001E) && att.GetPropertyString(0x3716001E) == "inline")) | |
{ | |
return true; | |
} | |
return false; | |
case BodyContentType.Rtf: | |
// If the body is RTF, then all OLE attachments are inline attachments. | |
// OLE attachments have 0x00000006 for the value of the PidTagAttachMethod property | |
if (att.Properties.ContainsKey(MapiPropertyTag.PR_ATTACH_METHOD)) | |
{ | |
return att.GetPropertyLong(MapiPropertyTag.PR_ATTACH_METHOD) == 0x00000006; | |
} | |
return false; | |
default: | |
throw new ArgumentOutOfRangeException(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Insert Header at Specific Location | |
MailMessage emailMessage = MailMessage.Load(fileName); | |
emailMessage.Headers.Insert("Received", "Value"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage mailMessage = MailMessage.Load(dataDir + "Attachments.eml"); | |
mailMessage.Save(dataDir + "LoadAndSaveFileAsEML_out.eml", SaveOptions.DefaultEml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance of SmtpClient class and load SMTP Authentication settings from Config file | |
SmtpClient client = new SmtpClient(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Data directory for reading and writing files | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage eml = MailMessage.Load(dataDir + "Message.eml"); | |
// Save the Email message to disk in ASCII format and Unicode format | |
eml.Save(dataDir + "AnEmail_out.msg", SaveOptions.DefaultMsgUnicode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Load Eml, html, mhtml, msg and dat file | |
MailMessage mailMessage = MailMessage.Load(dataDir + "Message.eml", new EmlLoadOptions()); | |
MailMessage.Load(dataDir + "description.html", new HtmlLoadOptions()); | |
MailMessage.Load(dataDir + "Message.mhtml", new MhtmlLoadOptions()); | |
MailMessage.Load(dataDir + "Message.msg", new MsgLoadOptions()); | |
// loading with custom options | |
EmlLoadOptions emlLoadOptions = new EmlLoadOptions | |
{ | |
PrefferedTextEncoding = Encoding.UTF8, | |
PreserveTnefAttachments = true | |
}; | |
MailMessage.Load(dataDir + "description.html", emlLoadOptions); | |
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions | |
{ | |
PrefferedTextEncoding = Encoding.UTF8, | |
ShouldAddPlainTextView = true, | |
PathToResources = dataDir | |
}; | |
MailMessage.Load(dataDir + "description.html", emlLoadOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Create an instance of MailMessage class | |
MailMessage message = new MailMessage {From = "sender@sender.com"}; | |
message.To.Add("receiver@gmail.com"); | |
// Load an attachment | |
Attachment attachment = new Attachment(dataDir + "1.txt"); | |
// Add Multiple Attachment in instance of MailMessage class and Save message to disk | |
message.Attachments.Add(attachment); | |
message.AddAttachment(new Attachment(dataDir + "1.jpg")); | |
message.AddAttachment(new Attachment(dataDir + "1.doc")); | |
message.AddAttachment(new Attachment(dataDir + "1.rar")); | |
message.AddAttachment(new Attachment(dataDir + "1.pdf")); | |
message.Save(dataDir + "outputAttachments_out.msg", SaveOptions.DefaultMsgUnicode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MailMessage mail = MailMessage.Load(dataDir + "tnefWithMsgInside.eml", new EmlLoadOptions() { PreserveEmbeddedMessageFormat = true }); | |
FileFormatType fileFormat = FileFormatUtil.DetectFileFormat(mail.Attachments[0].ContentStream).FileFormatType; | |
Console.WriteLine("Embedded message file format: " + fileFormat); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MailMessage mailMessage = MailMessage.Load(dataDir + "Attachments.eml"); | |
// Save as eml with preserved original boundares | |
EmlSaveOptions emlSaveOptions = new EmlSaveOptions(MailMessageSaveType.EmlFormat) | |
{ | |
PreserveOriginalBoundaries = true | |
}; | |
mailMessage.Save(dataDir + "PreserveOriginalBoundaries_out.eml", emlSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MailMessage mailMessage = MailMessage.Load(dataDir + "PreserveOriginalBoundaries.eml"); | |
// Save as eml with preserved attachment | |
EmlSaveOptions emlSaveOptions = new EmlSaveOptions(MailMessageSaveType.EmlFormat) | |
{ | |
FileCompatibilityMode = FileCompatibilityMode.PreserveTnefAttachments | |
}; | |
mailMessage.Save(dataDir + "PreserveTNEFAttachment_out.eml", emlSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
var eml = MailMessage.Load(dataDir + "sample.eml", new EmlLoadOptions()); | |
var options = MapiConversionOptions.UnicodeFormat; | |
//Preserve Embedded Message Format | |
options.PreserveEmbeddedMessageFormat = true; | |
//Convert EML to MSG with Options | |
var msg = MapiMessage.FromMailMessage(eml, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
const string pageHeader = @"<div><div class='pageHeader'>"Panditharatne, Mithra" <mithra.panditharatne@cibc.com><hr/></div>"; | |
MailMessage message = MailMessage.Load(dataDir + "Message.eml"); | |
MhtMessageFormatter mailFormatter = new MhtMessageFormatter(); | |
MailMessage copyMessage = message.Clone(); | |
mailFormatter.Format(copyMessage); | |
Console.WriteLine(copyMessage.HtmlBody.Contains(pageHeader) ? "True" : "False"); | |
MhtFormatOptions options = MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.WriteCompleteEmailAddress; | |
mailFormatter.Format(message, options); | |
if (!message.HtmlBody.Contains(pageHeader)) | |
Console.WriteLine("True"); | |
else | |
Console.WriteLine("False"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MsgLoadOptions options = new MsgLoadOptions(); | |
options.PreserveTnefAttachments = true; | |
MailMessage eml = MailMessage.Load(dataDir + "EmbeddedImage1.msg", options); | |
foreach (Attachment attachment in eml.Attachments) | |
{ | |
Console.WriteLine(attachment.Name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
List<Appointment> appointments = new List<Appointment>(); | |
CalendarReader reader = new CalendarReader(dataDir + "US-Holidays.ics"); | |
while (reader.NextEvent()) | |
{ | |
appointments.Add(reader.Current); | |
} | |
//working with appointments... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create the message | |
MailMessage msg = new MailMessage(); | |
msg.From = "sender@sender.com"; | |
msg.To = "receiver@receiver.com"; | |
msg.Subject = "the subject of the message"; | |
// Set delivery notifications for success and failed messages | |
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure; | |
// Add the MIME headers | |
msg.Headers.Add_("Disposition-Notification-To", "sender@sender.com"); | |
msg.Headers.Add_("Disposition-Notification-To", "sender@sender.com"); | |
// Send the message | |
SmtpClient client = new SmtpClient("host", "username", "password"); | |
client.Send(msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance of Attachment class | |
Attachment attachment; | |
// Load attachment to your Mail Message, Add attachment to your Mail Message and Remove attachment from your MailMessage | |
attachment = new Attachment(@"e:\1.txt"); | |
message.Attachments.Add(attachment); | |
message.Attachments.Remove(attachment); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
string dstEmailRemoved = dataDir + "RemoveAttachments.msg"; | |
// Create an instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
message.From = "sender@sender.com"; | |
message.To.Add("receiver@gmail.com"); | |
// Load an attachment | |
Attachment attachment = new Attachment(dataDir + "1.txt"); | |
// Add Multiple Attachment in instance of MailMessage class and Save message to disk | |
message.Attachments.Add(attachment); | |
message.AddAttachment(new Attachment(dataDir + "1.jpg")); | |
message.AddAttachment(new Attachment(dataDir + "1.doc")); | |
message.AddAttachment(new Attachment(dataDir + "1.rar")); | |
message.AddAttachment(new Attachment(dataDir + "1.pdf")); | |
// Remove attachment from your MailMessage and Save message to disk after removing a single attachment | |
message.Attachments.Remove(attachment); | |
message.Save(dstEmailRemoved, SaveOptions.DefaultMsgUnicode); | |
// Create a loop to display the no. of attachments present in email message | |
foreach (Attachment getAttachment in message.Attachments) | |
{ | |
// Save your attachments here and Display the the attachment file name | |
getAttachment.Save(dataDir + "/RemoveAttachments/" + "attachment_out" + getAttachment.Name); | |
Console.WriteLine(getAttachment.Name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
//sample input file | |
string fileName = "EmlWithLinkedResources.eml"; | |
//Load the test message with Linked Resources | |
MailMessage msg = MailMessage.Load(dataDir + fileName); | |
//Remove a LinkedResource | |
msg.LinkedResources.RemoveAt(0, true); | |
//Now clear the Alternate View for linked Resources | |
msg.AlternateViews[0].LinkedResources.Clear(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Email(); | |
//sample input file | |
string fileName = "EmlWithLinkedResources.eml"; | |
//Load the test message with Linked Resources | |
MailMessage msg = MailMessage.Load(dataDir + fileName); | |
//Remove a LinkedResource | |
msg.LinkedResources.RemoveAt(0, true); | |
//Now clear the Alternate View for linked Resources | |
msg.AlternateViews[0].LinkedResources.Clear(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Load attachment to your Mail Message, Add attachment and Remove attachment from your MailMessage | |
Attachment attachment = new Attachment(@"e:\1.txt"); | |
message.Attachments.Add(attachment); | |
message.Attachments.Remove(attachment); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
string fileName = "Meeting with Recurring Occurrences.msg"; | |
MailMessage msg = MailMessage.Load(dataDir + fileName); | |
MhtSaveOptions options = new MhtSaveOptions(); | |
{ | |
options.MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.RenderCalendarEvent; | |
//Format the output details if required - optional | |
//Set the display for Start Property | |
if (options.FormatTemplates.ContainsKey(MhtTemplateName.Start)) | |
options.FormatTemplates[MhtTemplateName.Start] = @"<span class='headerLineTitle'>Start:</span><span class='headerLineText'>{0}</span><br/>"; | |
else | |
options.FormatTemplates.Add(MhtTemplateName.Start, @"<span class='headerLineTitle'>Start:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for End Property | |
if (options.FormatTemplates.ContainsKey(MhtTemplateName.End)) | |
options.FormatTemplates[MhtTemplateName.End] = @"<span class='headerLineTitle'>End:</span><span class='headerLineText'>{0}</span><br/>"; | |
else | |
options.FormatTemplates.Add(MhtTemplateName.End, @"<span class='headerLineTitle'>End:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for Recurrence Property | |
if (options.FormatTemplates.ContainsKey(MhtTemplateName.Recurrence)) | |
options.FormatTemplates[MhtTemplateName.Recurrence] = @"<span class='headerLineTitle'>Recurrence:</span><span class='headerLineText'>{0}</span><br/>"; | |
else | |
options.FormatTemplates.Add(MhtTemplateName.Recurrence, @"<span class='headerLineTitle'>Recurrence:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for RecurrencePattern Property | |
if (options.FormatTemplates.ContainsKey(MhtTemplateName.RecurrencePattern)) | |
options.FormatTemplates[MhtTemplateName.RecurrencePattern] = @"<span class='headerLineTitle'>RecurrencePattern:</span><span class='headerLineText'>{0}</span><br/>"; | |
else | |
options.FormatTemplates.Add(MhtTemplateName.RecurrencePattern, @"<span class='headerLineTitle'>RecurrencePattern:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for Organizer Property | |
if (options.FormatTemplates.ContainsKey(MhtTemplateName.Organizer)) | |
options.FormatTemplates[MhtTemplateName.Organizer] = @"<span class='headerLineTitle'>Organizer:</span><span class='headerLineText'>{0}</span><br/>"; | |
else | |
options.FormatTemplates.Add(MhtTemplateName.Organizer, @"<span class='headerLineTitle'>Organizer:</span><span class='headerLineText'>{0}</span><br/>"); | |
//Set the display for RequiredAttendees Property | |
if (options.FormatTemplates.ContainsKey(MhtTemplateName.RequiredAttendees)) | |
options.FormatTemplates[MhtTemplateName.RequiredAttendees] = @"<span class='headerLineTitle'>RequiredAttendees:</span><span class='headerLineText'>{0}</span><br/>"; | |
else | |
options.FormatTemplates.Add(MhtTemplateName.RequiredAttendees, @"<span class='headerLineTitle'>RequiredAttendees:</span><span class='headerLineText'>{0}</span><br/>"); | |
}; | |
msg.Save(dataDir + "Meeting with Recurring Occurrences.mhtml", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an Instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Specify From, To, HtmlBody, DeliveryNotificationOptions field | |
message.From = "sender@sender.com"; | |
message.To.Add("receiver@receiver.com"); | |
message.HtmlBody = "<html><body>This is the Html body</body></html>"; | |
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess; | |
message.Headers.Add("Return-Receipt-To", "sender@sender.com"); | |
message.Headers.Add("Disposition-Notification-To", "sender@sender.com"); | |
// Create an instance of SmtpClient Class | |
SmtpClient client = new SmtpClient(); | |
// Specify your mailing host server, Username, Password and Port No | |
client.Host = "smtp.server.com"; | |
client.Username = "Username"; | |
client.Password = "Password"; | |
client.Port = 25; | |
try | |
{ | |
// Client.Send will send this message | |
client.Send(message); | |
// Display ‘Message Sent’, only if message sent successfully | |
Console.WriteLine("Message sent"); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Trace.WriteLine(ex.ToString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage message = MailMessage.Load(fileName); | |
string description = message.Attachments[0].Headers["Content-Description"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage message = MailMessage.Load(dataDir + "EmailWithAttandEmbedded.eml"); | |
string description = message.Attachments[0].Headers["Content-Description"]; | |
Console.WriteLine(description); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage eml = MailMessage.Load(dataDir + "Message.eml"); | |
eml.Save(dataDir + "AnEmail_out.mthml", SaveOptions.DefaultMhtml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
var fileName = "EmailWithAttandEmbedded.eml"; | |
var filePath = Path.Combine(dataDir, fileName); | |
MailMessage msg = MailMessage.Load(filePath); | |
var outFileName = Path.Combine(dataDir, fileName + ".html"); | |
var options = new HtmlSaveOptions() | |
{ | |
EmbedResources = false, | |
SaveResourceHandler = | |
(AttachmentBase attachment, out string resourcePath) => | |
{ | |
attachment.Save(Path.Combine(dataDir, attachment.ContentId)); | |
resourcePath = Path.Combine(".", attachment.ContentId); | |
} | |
}; | |
msg.Save(outFileName, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage message = MailMessage.Load(dataDir + "Message.eml"); | |
message.Save(dataDir + "SaveAsHTML_out.html", SaveOptions.DefaultHtml); | |
// OR | |
MailMessage eml = MailMessage.Load(dataDir + "Message.eml"); | |
HtmlSaveOptions options = SaveOptions.DefaultHtml; | |
options.EmbedResources = false; | |
options.HtmlFormatOptions = HtmlFormatOptions.WriteHeader | HtmlFormatOptions.WriteCompleteEmailAddress; //save the message headers to output HTML using the formatting options | |
eml.Save(dataDir + "SaveAsHTML1_out.html", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (MailMessage eml = new MailMessage("test@from.to", "test@to.to", "template subject", "Template body")) | |
{ | |
string oftEmlFileName = "EmlAsOft_out.oft"; | |
MsgSaveOptions options = SaveOptions.DefaultMsgUnicode; | |
options.SaveAsTemplate = true; | |
eml.Save(dataDir + oftEmlFileName, options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Data directory for reading and writing files | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage eml = MailMessage.Load(dataDir + "Message.eml"); | |
// Save as msg with preserved dates | |
MsgSaveOptions msgSaveOptions = new MsgSaveOptions(MailMessageSaveType.OutlookMessageFormatUnicode) | |
{ | |
PreserveOriginalDates = true | |
}; | |
eml.Save(Path.Combine(dataDir, "outTest_out.msg"), msgSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage(); | |
// Creates AlternateView to view an email message using the content specified in the //string | |
AlternateView alternate = AlternateView.CreateAlternateViewFromString("Alternate Text"); | |
// Adding alternate text | |
message.AlternateViews.Add(alternate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance of MailMessage | |
string fileName = RunExamples.GetDataDir_Email(); | |
MailMessage msg = new MailMessage(); | |
// Set the default or preferred encoding. This encoding will be used as the default for the from/to email addresses, subject and body of message. | |
msg.PreferredTextEncoding = Encoding.GetEncoding(28591); | |
// Set email addresses, subject and body | |
msg.From = new MailAddress("dmo@domain.com", "démo"); | |
msg.To.Add(new MailAddress("dmo@domain.com", "démo")); | |
msg.Subject = "démo"; | |
msg.HtmlBody = "démo"; | |
msg.Save(fileName + "SetDefaultTextEncoding_out.msg", SaveOptions.DefaultMsg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
// Create an instance MailMessage class | |
MailMessage mailMessage = new MailMessage(); | |
// Specify ReplyTo, From, To field, Cc and Bcc Addresses | |
mailMessage.ReplyToList.Add("reply@reply.com"); | |
mailMessage.From = "sender@sender.com"; | |
mailMessage.To.Add("receiver1@receiver.com"); | |
mailMessage.CC.Add("receiver2@receiver.com"); | |
mailMessage.Bcc.Add("receiver3@receiver.com"); | |
// Specify Date, Message subject, XMailer, Secret Header, Save message to disc | |
mailMessage.Subject = "test mail"; | |
mailMessage.Date = new System.DateTime(2006, 3, 6); | |
mailMessage.XMailer = "Aspose.Email"; | |
mailMessage.Headers.Add("secret-header", "mystery"); | |
mailMessage.Save(dataDir + "SetEmailHeaders_out.msg", SaveOptions.DefaultMsg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Declare message as MailMessage instance | |
MailMessage message = new MailMessage(); | |
// Specify HtmlBody | |
message.HtmlBody = "<html><body>This is the HTML body</body></html>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string location = "Room 5"; | |
DateTime startDate = new DateTime(2011, 12, 10, 10, 12, 11), | |
endDate = new DateTime(2012, 11, 13, 13, 11, 12); | |
MailAddress organizer = new MailAddress("aaa@amail.com", "Organizer"); | |
MailAddressCollection attendees = new MailAddressCollection(); | |
MailAddress attendee1 = new MailAddress("bbb@bmail.com", "First attendee"); | |
MailAddress attendee2 = new MailAddress("ccc@cmail.com", "Second attendee"); | |
attendee1.ParticipationStatus = ParticipationStatus.Accepted; | |
attendee2.ParticipationStatus = ParticipationStatus.Declined; | |
attendees.Add(attendee1); | |
attendees.Add(attendee2); | |
Appointment target = new Appointment(location, startDate, endDate, organizer, attendees); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.Priority = MailPriority.High; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.Sensitivity = MailSensitivity.Normal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.TextBody = "This is text body"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance of MailMessage class and Specify From, To, and HtmlBody field | |
MailMessage message = new MailMessage(); | |
message.From = "sender@sender.com"; | |
message.To.Add("receiver@receiver.com"); | |
message.HtmlBody = "<html><body>This is the HTML body</body></html>"; | |
// Create an instance of SmtpClient Class and Specify your mailing host server , User name, password and port # | |
SmtpClient client = new SmtpClient(); | |
client.Host = "smtp.server.com"; | |
client.Username = "Username"; | |
client.Password = "Password"; | |
client.Port = 25; | |
client.Send(message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string privateKeyFile = Path.Combine(RunExamples.GetDataDir_SMTP().Replace("_Send", string.Empty), RunExamples.GetDataDir_SMTP()+ "key2.pem"); | |
RSACryptoServiceProvider rsa = PemReader.GetPrivateKey(privateKeyFile); | |
DKIMSignatureInfo signInfo = new DKIMSignatureInfo("test", "yandex.ru"); | |
signInfo.Headers.Add("From"); | |
signInfo.Headers.Add("Subject"); | |
MailMessage mailMessage = new MailMessage("useremail@gmail.com", "test@gmail.com"); | |
mailMessage.Subject = "Signed DKIM message text body"; | |
mailMessage.Body = "This is a text body signed DKIM message"; | |
MailMessage signedMsg = mailMessage.DKIMSign(rsa, signInfo); | |
try | |
{ | |
SmtpClient client = new SmtpClient("smtp.gmail.com", 587, "your.email@gmail.com", "your.password"); | |
client.Send(signedMsg); | |
} | |
finally | |
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.Bcc.Add("Bcc1@receiver.com"); | |
message.Bcc.Add("Bcc2@receiver.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.CC.Add("CC1@receiver.com"); | |
message.CC.Add("CC2@receiver.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance of the MailMessage class | |
MailMessage message = new MailMessage(); | |
// Specify ReplyTo, from, To, Message subject and secret header field | |
message.ReplyToList.Add("reply@reply.com"); | |
message.From = "sender@sender.com"; | |
message.To.Add("receiver1@receiver.com"); | |
message.Subject = "test mail"; | |
message.Headers.Add("secret-header", "mystery"); | |
// Create an instance of the SmtpClient Class | |
SmtpClient client = new SmtpClient(); | |
// Specify your mailing host server, Username, Password, Port | |
client.Host = "smtp.server.com"; | |
client.Username = "Username"; | |
client.Password = "Password"; | |
client.Port = 25; | |
try | |
{ | |
// Client.Send will send this message | |
client.Send(message); | |
Console.WriteLine("Message sent"); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Trace.WriteLine(ex.ToString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an Instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Specify From, To, HtmlBody, BodyEncoding field | |
message.From = "sender@sender.com"; | |
message.To.Add("receiver@receiver.com"); | |
message.HtmlBody = "<html><body>This is the Html body</body></html>"; | |
message.BodyEncoding = Encoding.ASCII; | |
// Create an instance of SmtpClient Class and Specify your mailing host server, Username, Password and Port | |
SmtpClient client = new SmtpClient(); | |
client.Host = "smtp.server.com"; | |
client.Username = "Username"; | |
client.Password = "Password"; | |
client.Port = 25; | |
// Client.Send will send this message | |
client.Send(message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Declare message as MailMessage instance | |
// Create an Instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
// Specify From address | |
message.From = "sender@sender.com"; | |
// Specify recipients’ mail addresses | |
message.To.Add("receiver1@receiver.com"); | |
message.To.Add("receiver2@receiver.com"); | |
message.To.Add("receiver3@receiver.com"); | |
// Specify CC addresses | |
message.CC.Add("CC1@receiver.com"); | |
message.CC.Add("CC2@receiver.com"); | |
// Specify BCC addresses | |
message.Bcc.Add("Bcc1@receiver.com"); | |
message.Bcc.Add("Bcc2@receiver.com"); | |
// Create an instance of SmtpClient Class | |
SmtpClient client = new SmtpClient(); | |
// Specify your mailing host server, Username, Password, Port | |
client.Host = "smtp.server.com"; | |
client.Username = "Username"; | |
client.Password = "Password"; | |
client.Port = 25; | |
try | |
{ | |
// Client.Send will send this message | |
client.Send(message); | |
// Display ‘Message Sent’, only if message sent successfully | |
Console.WriteLine("Message sent"); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Trace.WriteLine(ex.ToString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set the client timeout | |
client.Timeout = 10000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public void TestUpdateResources() | |
{ | |
string fileName = "ExchangeMessage.eml"; | |
string imgFileName = "Untitled.png"; | |
string outFileName = "01_ExchangeMessage_SAVE_Preserve.eml"; | |
MailMessage originalMailMessage = MailMessage.Load(fileName); | |
UpdateResources(originalMailMessage, imgFileName); | |
EmlSaveOptions emlSo = new EmlSaveOptions(MailMessageSaveType.EmlFormat); | |
emlSo.FileCompatibilityMode = FileCompatibilityMode.PreserveTnefAttachments; | |
originalMailMessage.Save(outFileName, emlSo); | |
} | |
private static void UpdateResources(MailMessage msg, string imgFileName) | |
{ | |
for (int i = 0; i < msg.Attachments.Count; i++) | |
{ | |
if ((msg.Attachments[i].ContentType.MediaType == "image/png") || (msg.Attachments[i].ContentType.MediaType == "application/octet-stream" && Path.GetExtension(msg.Attachments[i].ContentType.Name) == ".jpg")) | |
{ | |
msg.Attachments[i].ContentStream = new MemoryStream(File.ReadAllBytes(imgFileName)); | |
} | |
else if ((msg.Attachments[i].ContentType.MediaType == "message/rfc822") || (msg.Attachments[i].ContentType.MediaType == "application/octet-stream" && Path.GetExtension(msg.Attachments[i].ContentType.Name) == ".msg")) | |
{ | |
MemoryStream ms = new MemoryStream(); | |
msg.Attachments[i].Save(ms); | |
ms.Position = 0; | |
MailMessage embeddedMessage = MailMessage.Load(ms); | |
UpdateResources(embeddedMessage, imgFileName); | |
MemoryStream msProcessedEmbedded = new MemoryStream(); | |
embeddedMessage.Save(msProcessedEmbedded, Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode); | |
msProcessedEmbedded.Position = 0; | |
msg.Attachments[i].ContentStream = msProcessedEmbedded; | |
} | |
} | |
foreach (LinkedResource att in msg.LinkedResources) | |
{ | |
if (att.ContentType.MediaType == "image/png") | |
att.ContentStream = new MemoryStream(File.ReadAllBytes(imgFileName)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public static void TestUpdateResources(string dataDir) | |
{ | |
string fileName = dataDir + "tnefEML1.eml"; | |
string imgFileName = dataDir + "Untitled.jpg"; | |
string outFileName = dataDir + "UpdateTNEFAttachments_out.eml"; | |
MailMessage originalMailMessage = MailMessage.Load(fileName); | |
UpdateResources(originalMailMessage, imgFileName); | |
EmlSaveOptions emlSo = new EmlSaveOptions(MailMessageSaveType.EmlFormat); | |
emlSo.FileCompatibilityMode = FileCompatibilityMode.PreserveTnefAttachments; | |
originalMailMessage.Save(outFileName, emlSo); | |
} | |
private static void UpdateResources(MailMessage msg, string imgFileName) | |
{ | |
for (int i = 0; i < msg.Attachments.Count; i++) | |
{ | |
if ((msg.Attachments[i].ContentType.MediaType == "image/png") || (msg.Attachments[i].ContentType.MediaType == "application/octet-stream" && Path.GetExtension(msg.Attachments[i].ContentType.Name) == ".jpg")) | |
{ | |
msg.Attachments[i].ContentStream = new MemoryStream(File.ReadAllBytes(imgFileName)); | |
} | |
else if ((msg.Attachments[i].ContentType.MediaType == "message/rfc822") || (msg.Attachments[i].ContentType.MediaType == "application/octet-stream" && Path.GetExtension(msg.Attachments[i].ContentType.Name) == ".msg")) | |
{ | |
MemoryStream ms = new MemoryStream(); | |
msg.Attachments[i].Save(ms); | |
ms.Position = 0; | |
MailMessage embeddedMessage = MailMessage.Load(ms); | |
UpdateResources(embeddedMessage, imgFileName); | |
MemoryStream msProcessedEmbedded = new MemoryStream(); | |
embeddedMessage.Save(msProcessedEmbedded, SaveOptions.DefaultMsgUnicode); | |
msProcessedEmbedded.Position = 0; | |
msg.Attachments[i].ContentStream = msProcessedEmbedded; | |
} | |
} | |
foreach (LinkedResource att in msg.LinkedResources) | |
{ | |
if (att.ContentType.MediaType == "image/png") | |
att.ContentStream = new MemoryStream(File.ReadAllBytes(imgFileName)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create a new message | |
MailMessage message = new MailMessage(); | |
message.From = "sender@gmail.com"; | |
message.To = "receiver@gmail.com"; | |
message.Subject = "Using MailMessage Features"; | |
// Specify message date | |
message.Date = DateTime.Now; | |
// Specify message priority | |
message.Priority = MailPriority.High; | |
// Specify message sensitivity | |
message.Sensitivity = MailSensitivity.Normal; | |
// Specify options for delivery notifications | |
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string privateCertFile = @"D:\Certificates\dr38445\dr38445.pfx"; | |
X509Certificate2 privateCert = new X509Certificate2(privateCertFile, "3p8a4s4s5word"); | |
MailMessage msg = new MailMessage("dr38445@gmail.com", "dr38445@gmail.com", "subject:Signed message only by AE", "body:Test Body of signed message by AE"); | |
MailMessage signed = msg.AttachSignature(privateCert, true); | |
SmtpClient smtp = GetSmtpClientDr38445(); // some test account | |
smtp.Send(signed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create an instance of the MailMessage class | |
MailMessage message = new MailMessage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
EmailValidator ev = new EmailValidator(); | |
ValidationResult result; | |
ev.Validate("user@domain.com", out result); | |
if (result.ReturnCode == ValidationResponseCode.ValidationSuccess) | |
{ | |
Console.WriteLine("the email address is valid."); | |
} | |
else | |
{ | |
Console.WriteLine("the mail address is invalid,for the {0}", result.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
Aspose.Email.Verifications.EmailValidator ev = new Aspose.Email.Verifications.EmailValidator(); | |
Aspose.Email.Verifications.ValidationResult result; | |
try | |
{ | |
ev.Validate(txtEmailAdr.Text, out result); | |
if (result.ReturnCode == ValidationResponseCode.ValidationSuccess) | |
{ | |
lblResult.Text = "The email address is valid."; | |
} | |
else | |
{ | |
lblResult.Text = "The mail address is invalid,return code is : " + result.ReturnCode + "."; | |
} | |
} | |
catch (Exception ex) | |
{ | |
lblResult.Text += "<br>" + ex.Message; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials and Get Exchange mailbox info of other email account | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username","Username", "password", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo("otherUser@domain.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials and Get Exchange mailbox info of other email account | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo("otherUser@domain.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create ExchangeMailboxInfo, ExchangeMessageInfoCollection instance | |
ExchangeMailboxInfo mailbox = client.GetMailboxInfo(); | |
ExchangeMessageInfoCollection messages = null; | |
ExchangeFolderInfo subfolderInfo = new ExchangeFolderInfo(); | |
// Check if specified custom folder exisits and Get all the messages info from the target Uri | |
client.FolderExists(mailbox.InboxUri, "TestInbox", out subfolderInfo); | |
messages = client.FindMessages(subfolderInfo.Uri); | |
// Parse all the messages info collection | |
foreach (ExchangeMessageInfo info in messages) | |
{ | |
string strMessageURI = info.UniqueUri; | |
// now get the message details using FetchMessage() | |
MailMessage msg = client.FetchMessage(strMessageURI); | |
Console.WriteLine("Subject: " + msg.Subject); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set mailboxURI, Username, password, domain information | |
string mailboxUri = "https://ex2010/ews/exchange.asmx"; | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
//Create New Contact | |
Contact contact = new Contact(); | |
//Set general info | |
contact.Gender = Gender.Male; | |
contact.DisplayName = "Frank Lin"; | |
contact.CompanyName = "ABC Co."; | |
contact.JobTitle = "Executive Manager"; | |
//Add Phone numbers | |
contact.PhoneNumbers.Add(new PhoneNumber { Number = "123456789", Category = PhoneNumberCategory.Home }); | |
//contact's associated persons | |
contact.AssociatedPersons.Add(new AssociatedPerson { Name = "Catherine", Category = AssociatedPersonCategory.Spouse }); | |
contact.AssociatedPersons.Add(new AssociatedPerson { Name = "Bob", Category = AssociatedPersonCategory.Child }); | |
contact.AssociatedPersons.Add(new AssociatedPerson { Name = "Merry", Category = AssociatedPersonCategory.Sister }); | |
//URLs | |
contact.Urls.Add(new Url { Href = "www.blog.com", Category = UrlCategory.Blog }); | |
contact.Urls.Add(new Url { Href = "www.homepage.com", Category = UrlCategory.HomePage }); | |
//Set contact's Email address | |
contact.EmailAddresses.Add(new EmailAddress { Address = "Frank.Lin@Abc.com", DisplayName = "Frank Lin", Category = EmailAddressCategory.Email1 }); | |
try | |
{ | |
client.CreateContact(contact); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (IEWSClient client = EWSClient.GetEWSClient("exchange.domain.com/ews/Exchange.asmx", "username", "password", "")) | |
{ | |
client.AddHeader("X-AnchorMailbox", "username@domain.com"); | |
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.Add("address4@host.com"); | |
newMembers.Add("address5@host.com"); | |
client.AddToDistributionList(distributionLists[0], newMembers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.Id = "list's id"; | |
distributionList.ChangeKey = "list's change key"; | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.Add("address6@host.com"); | |
client.AddToDistributionList(distributionList, newMembers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Get email delivery notifications | |
builder.ContentClass.Equals(ContentClassType.MDN.ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string hamFolder = @"D:\ham"; | |
string spamFolder = @"D:\spam"; | |
string testFolder = @"D:\test"; | |
string dataBaseFile = @"D:\SpamFilterDatabase.txt"; | |
TeachAndCreateDatabase(hamFolder, spamFolder, dataBaseFile); | |
string[] testFiles = Directory.GetFiles(testFolder, "*.eml"); | |
SpamAnalyzer analyzer = new SpamAnalyzer(dataBaseFile); | |
foreach (string file in testFiles) | |
{ | |
MailMessage msg = MailMessage.Load(file); | |
Console.WriteLine(msg.Subject); | |
double probability = analyzer.Test(msg); | |
PrintResult(probability); | |
} | |
private static void TeachAndCreateDatabase(string hamFolder, string spamFolder, string dataBaseFile) | |
{ | |
string[] hamFiles = Directory.GetFiles(hamFolder, "*.eml"); | |
string[] spamFiles = Directory.GetFiles(spamFolder, "*.eml"); | |
SpamAnalyzer analyzer = new SpamAnalyzer(); | |
for (int i = 0; i < hamFiles.Length; i++) | |
{ | |
MailMessage hamMailMessage; | |
try | |
{ | |
hamMailMessage = MailMessage.Load(hamFiles[i]); | |
} | |
catch (Exception) | |
{ | |
continue; | |
} | |
Console.WriteLine(i); | |
analyzer.TrainFilter(hamMailMessage, false); | |
} | |
for (int i = 0; i < spamFiles.Length; i++) | |
{ | |
MailMessage spamMailMessage; | |
try | |
{ | |
spamMailMessage = MailMessage.Load(hamFiles[i]); | |
} | |
catch (Exception) | |
{ | |
continue; | |
} | |
Console.WriteLine(i); | |
analyzer.TrainFilter(spamMailMessage, true); | |
} | |
analyzer.SaveDatabase(dataBaseFile); | |
} | |
private static void PrintResult(double probability) | |
{ | |
if (probability < 0.05) | |
Console.WriteLine("This is ham)"); | |
else if (probability > 0.95) | |
Console.WriteLine("This is spam)"); | |
else | |
Console.WriteLine("Maybe spam)"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage mailMessageOrig = MailMessage.Load(Path.Combine(TestUtil.GetTestDataPath(), "Mail.msg"), MailMessageLoadOptions.DefaultMsg); | |
X509Certificate2 certificate = CryptographyTestCertificate(); | |
Assert.False(mailMessageOrig.IsEncrypted); | |
mailMessage = mailMessageOrig.Encrypt(certificate); | |
Assert.True(mailMessage.IsEncrypted); | |
mailMessage = mailMessage.Decrypt(certificate); | |
Assert.False(mailMessage.IsEncrypted); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Connect to Exchange Server using ImapClient class | |
ImapClient imapClient = new ImapClient("ex07sp1", "Administrator", "Evaluation1"); | |
imapClient.SecurityOptions = SecurityOptions.Auto; | |
// Select the Inbox folder | |
imapClient.SelectFolder(ImapFolderInfo.InBox); | |
// Get the list of messages | |
ImapMessageInfoCollection msgCollection = imapClient.ListMessages(); | |
foreach (ImapMessageInfo msgInfo in msgCollection) | |
{ | |
Console.WriteLine(msgInfo.Subject); | |
} | |
// Disconnect from the server | |
imapClient.Dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
static void GetExchangeClient() | |
{ | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username","Username", "password", "domain"); | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
static IEWSClient GetExchnageEWSClient() | |
{ | |
const string mailboxUri = "https://outlook.office365.com/ews/exchange.asmx"; | |
const string domain = @""; | |
const string username = @"username@ASE305.onmicrosoft.com"; | |
const string password = @"password"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage eml = MailMessage.Load(Path.Combine(directoryPath, "test.eml")); | |
// Save as mht with header | |
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions | |
{ | |
// Check the body encoding for validity. | |
MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader, | |
CheckBodyContentEncoding = true | |
}; | |
eml.Save(Path.Combine(directoryPath, "outTest.mht"), mhtSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeWebServiceClient client = GetAsposeEWSClient(); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Find those Conversation Items in the Inbox folder which we want to copy | |
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri); | |
foreach (ExchangeConversation conversation in conversations) | |
{ | |
Console.WriteLine("Topic: " + conversation.ConversationTopic); | |
// Copy the conversation item based on some condition | |
if (conversation.ConversationTopic.Contains("test email") == true) | |
{ | |
client.CopyConversationItems(conversation.ConversationId, client.MailboxInfo.DeletedItemsUri); | |
Console.WriteLine("Copied the conversation item to another folder"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
try | |
{ | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MailMessage message = new MailMessage("from@domain.com", "to@domain.com", "EMAILNET-34997 - " + Guid.NewGuid().ToString(), "EMAILNET-34997 Exchange: Copy a message and get reference to the new Copy item"); | |
string messageUri = client.AppendMessage(message); | |
string newMessageUri = client.CopyItem(messageUri, client.MailboxInfo.DeletedItemsUri); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string address = "firstname.lastname@aspose.com"; | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MailMessage message = CreateTestMessage(address); | |
// Set FollowUpOptions Buttons | |
FollowUpOptions options = new FollowUpOptions(); | |
options.VotingButtons = "Yes;No;Maybe;Exactly!"; | |
client.Send(message, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
private static MapiMessage CreateTestMessage(bool draft) | |
{ | |
MapiMessage msg = new MapiMessage("from@test.com","to@test.com","Flagged message","Make it nice and short, but descriptive. The description may appear in search engines' search results pages..."); | |
if (!draft) | |
{ | |
msg.SetMessageFlags(msg.Flags ^ MapiMessageFlags.MSGFLAG_UNSENT); | |
} | |
return msg; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
string inbox = client.MailboxInfo.InboxUri; | |
string folderName1 = "EMAILNET-35054"; | |
string subFolderName0 = "2015"; | |
string folderName2 = folderName1 + "/" + subFolderName0; | |
string folderName3 = folderName1 + " / 2015"; | |
ExchangeFolderInfo rootFolderInfo = null; | |
ExchangeFolderInfo folderInfo = null; | |
try | |
{ | |
client.UseSlashAsFolderSeparator = true; | |
client.CreateFolder(client.MailboxInfo.InboxUri, folderName1); | |
client.CreateFolder(client.MailboxInfo.InboxUri, folderName2); | |
} | |
finally | |
{ | |
if (client.FolderExists(inbox, folderName1, out rootFolderInfo)) | |
{ | |
if (client.FolderExists(inbox, folderName2, out folderInfo)) | |
client.DeleteFolder(folderInfo.Uri, true); | |
client.DeleteFolder(rootFolderInfo.Uri, true); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
String id = distributionLists[0].Id; | |
MailAddress distributionListAddress = new MailAddress("privateDL", true); | |
distributionListAddress.Id.EWSId = id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = GetAsposeEWSClient(); | |
Console.WriteLine("Connected to Exchange server"); | |
InboxRule rule = new InboxRule(); | |
rule.DisplayName = "Message from client ABC"; | |
// Set Subject contains, From address is administrator@ex2010.local and Add the conditions | |
RulePredicates newRules = new RulePredicates(); | |
newRules.ContainsSubjectStrings.Add("ABC"); | |
newRules.FromAddresses.Add(new MailAddress("administrator@ex2010.local", true)); | |
rule.Conditions = newRules; | |
// Add Actions Move the message to a folder and Add the actions | |
RuleActions newActions = new RuleActions(); | |
newActions.MoveToFolder = "120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA=="; | |
rule.Actions = newActions; | |
client.CreateInboxRule(rule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.DisplayName = "test private list"; | |
MailAddressCollection members = new MailAddressCollection(); | |
members.Add("address1@host.com"); | |
members.Add("address2@host.com"); | |
members.Add("address3@host.com"); | |
client.CreateDistributionList(distributionList, members); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
const string mailboxUri = "https://exchange.domain.com/ews/Exchange.asmx"; | |
const string domain = @""; | |
const string username = @"username"; | |
const string password = @"password"; | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credential); | |
try | |
{ | |
MailMessage message = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + Guid.NewGuid().ToString(),"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
client.Send(message); | |
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
if (messageInfoCol.Count == 1) | |
Console.WriteLine("1 message in Inbox"); | |
else | |
Console.WriteLine("Error! No message in Inbox"); | |
MailMessage message1 = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + Guid.NewGuid().ToString(),"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
client.Send(message1); | |
messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
if (messageInfoCol.Count == 2) | |
Console.WriteLine("2 messages in Inbox"); | |
else | |
Console.WriteLine("Error! No new message in Inbox"); | |
MailMessage message2 = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + Guid.NewGuid().ToString(),"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
message2.Attachments.Add(Attachment.CreateAttachmentFromString("Test attachment 1", "Attachment Name 1")); | |
message2.Attachments.Add(Attachment.CreateAttachmentFromString("Test attachment 2", "Attachment Name 2")); | |
// Reply, Replay All and forward Message | |
client.Reply(message2, messageInfoCol[0]); | |
client.ReplyAll(message2, messageInfoCol[0]); | |
client.Forward(message2, messageInfoCol[0]); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Error in program"+ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create the User Configuration for Inbox folder | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri); | |
UserConfiguration userConfig = new UserConfiguration(userConfigName); | |
userConfig.Dictionary.Add("key1", "value1"); | |
userConfig.Dictionary.Add("key2", "value2"); | |
userConfig.Dictionary.Add("key3", "value3"); | |
client.CreateUserConfiguration(userConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
string strContactToDelete = "John Teddy"; | |
Contact[] contacts = client.GetContacts(client.MailboxInfo.ContactsUri); | |
foreach (Contact contact in contacts) | |
{ | |
if (contact.DisplayName.Equals(strContactToDelete)) | |
client.DeleteContact(contact); | |
} | |
client.Dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeWebServiceClient client = GetAsposeEWSClient(); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Find those Conversation Items in the Inbox folder which we want to delete | |
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri); | |
foreach (ExchangeConversation conversation in conversations) | |
{ | |
Console.WriteLine("Topic: " + conversation.ConversationTopic); | |
// Delete the conversation item based on some condition | |
if (conversation.ConversationTopic.Contains("test email") == true) | |
{ | |
client.DeleteConversationItems(conversation.ConversationId); | |
Console.WriteLine("Deleted the conversation item"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
MailAddressCollection members = client.FetchDistributionList(distributionLists[0]); | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
membersToDelete.Add(members[0]); | |
membersToDelete.Add(members[1]); | |
client.DeleteFromDistributionList(distributionLists[0], membersToDelete); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.Id = "list's id"; | |
distributionList.ChangeKey = "list's change key"; | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
MailAddress addressToDelete = new MailAddress("address", true); | |
//addressToDelete.Id.EWSId = "member's id"; | |
membersToDelete.Add(addressToDelete); | |
client.AddToDistributionList(distributionList, membersToDelete); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of IEWSClient class by giving credentials | |
string mailboxURI = "https://Ex2003/exchange/administrator"; // WebDAV | |
string username = "administrator"; | |
string password = "pwd"; | |
string domain = "domain.local"; | |
Console.WriteLine("Connecting to Exchange Server...."); | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
ExchangeClient client = new ExchangeClient(mailboxURI, credential); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
// List all messages from Inbox folder | |
Console.WriteLine("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri); | |
foreach (ExchangeMessageInfo msgInfo in msgInfoColl) | |
{ | |
// Delete message based on some criteria | |
if (msgInfo.Subject != null && msgInfo.Subject.ToLower().Contains("delete") == true) | |
{ | |
client.DeleteMessage(msgInfo.UniqueUri); | |
Console.WriteLine("Message deleted...." + msgInfo.Subject); | |
} | |
else | |
{ | |
// Do something else | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
// List all messages from Inbox folder | |
Console.WriteLine("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri); | |
foreach (ExchangeMessageInfo msgInfo in msgInfoColl) | |
{ | |
// Delete message based on some criteria | |
if (msgInfo.Subject != null && msgInfo.Subject.ToLower().Contains("delete") == true) | |
{ | |
client.DeleteMessage(msgInfo.UniqueUri); // EWS | |
Console.WriteLine("Message deleted...." + msgInfo.Subject); | |
} | |
else | |
{} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
client.DeleteDistributionList(distributionLists[0],true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks info collection from exchange | |
ExchangeMessageInfoCollection tasks = client.ListMessages(client.MailboxInfo.TasksUri); | |
// Parse all the tasks info in the list | |
foreach (ExchangeMessageInfo info in tasks) | |
{ | |
// Fetch task from exchange using current task info | |
ExchangeTask task = client.FetchTask(info.UniqueUri); | |
if (task.Subject.Equals("test")) | |
{ | |
client.DeleteTask(task.UniqueUri, DeleteTaskOptions.DeletePermanently); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Delete User Configuration | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri); | |
client.DeleteUserConfiguration(userConfigName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.Id = "list's id"; | |
client.DeleteDistributionList(distributionList,true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.Bcc.Add("CC1@receiver.com"); | |
message.Bcc.Add("CC2@receiver.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of IEWSClient class by giving credentials | |
string mailboxURI = "http:// Ex2003/exchange/administrator"; // WebDAV | |
// Register callback method for SSL validation event | |
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationHandler; | |
try | |
{ | |
DownloadAllMessages(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
static string username = "administrator"; | |
static string password = "pwd"; | |
static string domain = "ex2010.local"; | |
private static string dataDir = RunExamples.GetDataDir_Exchange(); | |
public static void Run() | |
{ | |
// Register callback method for SSL validation event | |
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationHandler; | |
try | |
{ | |
DownloadAllMessages(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
private static void DownloadAllMessages() | |
{ | |
try | |
{ | |
string rootFolder = domain + "-" + username; | |
Directory.CreateDirectory(rootFolder); | |
string inboxFolder = rootFolder + "\\Inbox"; | |
Directory.CreateDirectory(inboxFolder); | |
Console.WriteLine("Downloading all messages from Inbox...."); | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", username, password, domain); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri); | |
string rootUri = client.GetMailboxInfo().RootUri; | |
// List all the folders from Exchange server | |
ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(rootUri); | |
foreach (ExchangeFolderInfo folderInfo in folderInfoCollection) | |
{ | |
// Call the recursive method to read messages and get sub-folders | |
ListMessagesInFolder(client, folderInfo, rootFolder); | |
} | |
Console.WriteLine("All messages downloaded."); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
// Recursive method to get messages from folders and sub-folders | |
private static void ListMessagesInFolder(IEWSClient client, ExchangeFolderInfo folderInfo, string rootFolder) | |
{ | |
// Create the folder in disk (same name as on IMAP server) | |
string currentFolder = rootFolder + "\\" + folderInfo.DisplayName; | |
Directory.CreateDirectory(currentFolder); | |
// List messages | |
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(folderInfo.Uri); | |
Console.WriteLine("Listing messages...."); | |
int i = 0; | |
foreach (ExchangeMessageInfo msgInfo in msgInfoColl) | |
{ | |
// Get subject and other properties of the message | |
Console.WriteLine("Subject: " + msgInfo.Subject); | |
// Get rid of characters like ? and :, which should not be included in a file name | |
string fileName = msgInfo.Subject.Replace(":", " ").Replace("?", " "); | |
MailMessage msg = client.FetchMessage(msgInfo.UniqueUri); | |
msg.Save(dataDir + "\\" + fileName + "-" + i + ".msg"); | |
i++; | |
} | |
Console.WriteLine("============================\n"); | |
try | |
{ | |
// If this folder has sub-folders, call this method recursively to get messages | |
ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderInfo.Uri); | |
foreach (ExchangeFolderInfo subfolderInfo in folderInfoCollection) | |
{ | |
ListMessagesInFolder(client, subfolderInfo, currentFolder); | |
} | |
} | |
catch (Exception) | |
{} | |
} | |
private static bool RemoteCertificateValidationHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) | |
{ | |
return true; // Ignore the checks and go ahead | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public static string dataDir = RunExamples.GetDataDir_Exchange(); | |
public static string mailboxUri = "https://exchange/ews/exchange.asmx"; // EWS | |
public static string username = "administrator"; | |
public static string password = "pwd"; | |
public static string domain = "ex2013.local"; | |
public static void Run() | |
{ | |
try | |
{ | |
ReadPublicFolders(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
private static void ReadPublicFolders() | |
{ | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credential); | |
ExchangeFolderInfoCollection folders = client.ListPublicFolders(); | |
foreach (ExchangeFolderInfo publicFolder in folders) | |
{ | |
Console.WriteLine("Name: " + publicFolder.DisplayName); | |
Console.WriteLine("Subfolders count: " + publicFolder.ChildFolderCount); | |
ListMessagesFromSubFolder(publicFolder, client); | |
} | |
} | |
private static void ListMessagesFromSubFolder(ExchangeFolderInfo publicFolder, IEWSClient client) | |
{ | |
Console.WriteLine("Folder Name: " + publicFolder.DisplayName); | |
ExchangeMessageInfoCollection msgInfoCollection = client.ListMessagesFromPublicFolder(publicFolder); | |
foreach (ExchangeMessageInfo messageInfo in msgInfoCollection) | |
{ | |
MailMessage msg = client.FetchMessage(messageInfo.UniqueUri); | |
Console.WriteLine(msg.Subject); | |
msg.Save(dataDir + msg.Subject + ".msg", SaveOptions.DefaultMsgUnicode); | |
} | |
// Call this method recursively for any subfolders | |
if (publicFolder.ChildFolderCount > 0) | |
{ | |
ExchangeFolderInfoCollection subfolders = client.ListSubFolders(publicFolder); | |
foreach (ExchangeFolderInfo subfolder in subfolders) | |
{ | |
ListMessagesFromSubFolder(subfolder, client); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Send message with the requested read receipt | |
MailMessage mailMessage = new MailMessage("fromAddress", "toAddress", "test MDN","This is a test message with read receipt requested"); | |
// request the read receipt | |
mailMessage.ReadReceiptTo = "fromAddress"; | |
SendMessage(mailMessage, SendMethod.SMTP); | |
// Add multiple ReadReceiptTo addresses. Send message with the requested read receipt. | |
mailMessage = new MailMessage("fromAddress", "toAddress", "test MDN","This is a test message with read receipt requested"); | |
var addressCollection = new Aspose.Email.Mail.MailAddressCollection(); | |
addressCollection.Add("fromAddress"); | |
addressCollection.Add(anotherAddress); | |
mailMessage.ReadReceiptTo = addressCollection; | |
SendMessage(mailMessage, SendMethod.SMTP); | |
// Send message by Exchange | |
mailMessage = new MailMessage("fromAddress", "toAddress", "test MDN","This is a test message with read receipt requested"); | |
mailMessage.ReadReceiptTo = "fromAddress"; | |
SendMessage(mailMessage, SendMethod.Exchange); | |
// Check the request, create and send read receipt. | |
MailMessage emlMDN = FetchMessage(); | |
if (emlMDN.ReadReceiptTo.Count > 0) | |
{ | |
SendMessage(emlMDN.CreateReadReceipt("toAddress", null), SendMethod.SMTP); | |
} | |
// Create the MapiMessage with requested read receipt | |
MapiMessage mapiMessage = new MapiMessage("fromAddress", "toAddress", "test MDN", "This is a read requested mapiMessage", OutlookMessageFormat.Unicode); | |
mapiMessage.ReadReceiptRequested = true; | |
// Create the MailMessage with requested read receipt and convert it to MapiMessage | |
mailMessage = new MailMessage("fromAddress", "toAddress", "test MDN","This is a test message with read receipt requested"); | |
mailMessage.ReadReceiptTo = "fromAddress"; | |
mapiMessage = MapiMessage.FromMailMessage(mailMessage, MapiConversionOptions.UnicodeFormat); | |
mapiMessage = new MapiMessage("dmitry.samodurov@aspose.com", "dmitry.samodurov@aspose.com", "test MDN", "This is a read requested mapiMessage", OutlookMessageFormat.Unicode); | |
mapiMessage.ReadReceiptRequested = true; | |
var getData = MailMessageInterpretorFactory.Instance.GetIntepretor(mapiMessage.MessageClass); | |
var getMessage = mi.Interpret(mapiMessage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeWebServiceClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.GetMailboxInfo().InboxUri); | |
try | |
{ | |
int itemsPerPage = 5; | |
List<ExchangeMessageInfoCollection> pages = new List<ExchangeMessageInfoCollection>(); | |
ExchangeMessageInfoCollection pagedMessageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, itemsPerPage); | |
pages.Add(pagedMessageInfoCol); | |
while (!pagedMessageInfoCol.LastPage) | |
{ | |
pagedMessageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, itemsPerPage, pagedMessageInfoCol.LastItemOffset.Value + 1); | |
pages.Add(pagedMessageInfoCol); | |
} | |
pagedMessageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, itemsPerPage); | |
while (!pagedMessageInfoCol.LastPage) | |
{ | |
client.ListMessages(client.MailboxInfo.InboxUri, pagedMessageInfoCol, itemsPerPage, pagedMessageInfoCol.LastItemOffset.Value + 1); | |
} | |
} | |
finally | |
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
static void Main(string[] args) | |
{ | |
var NewThread = new Thread(Run); | |
NewThread.SetApartmentState(ApartmentState.STA); | |
NewThread.Start(); | |
NewThread.Join(); | |
} | |
static void Run() | |
{ | |
string authority = ConfigurationManager.AppSettings["authority"]; | |
string clientID = ConfigurationManager.AppSettings["clientID"]; | |
Uri clientAppUri = new Uri(ConfigurationManager.AppSettings["clientAppUri"]); | |
string resource = ConfigurationManager.AppSettings["resource"]; | |
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false); | |
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resource, clientID, clientAppUri); | |
OAuthNetworkCredential oAuthCredential = new OAuthNetworkCredential(authenticationResult.AccessToken); | |
using (IEWSClient client = EWSClient.GetEWSClient(resource + "ews/exchange.asmx", oAuthCredential)) | |
{ | |
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://Servername/exchange/username","username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to get Message URI | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMessageURI = msgInfo.UniqueUri; | |
// Now save the message in disk | |
client.SaveMessage(strMessageURI, dataDir + msgInfo.MessageId + ".eml"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://Servername/exchange/username","username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMessageURI = msgInfo.UniqueUri; | |
client.SaveMessage(strMessageURI, dataDir + msgInfo.MessageId + ".eml"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of IEWSClient class by providing credentials | |
const string mailboxUri = "https://ews.domain.com/ews/Exchange.asmx"; | |
const string domain = @""; | |
const string username = @"username"; | |
const string password = @"password"; | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credential); | |
// Get Exchange mailbox info of other email account | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
ExchangeFolderInfo info = client.GetFolderInfo(mailboxInfo.InboxUri); | |
ExchangeFolderInfoCollection fc = new ExchangeFolderInfoCollection(); | |
fc.Add(info); | |
client.Backup(fc, dataDir + "Backup_out.pst", Aspose.Email.Outlook.Pst.BackupOptions.None); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance's of EWSClient class by giving credentials | |
IEWSClient client1 = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser1", "pwd", "domain"); | |
IEWSClient client2 = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser2", "pwd", "domain"); | |
{ | |
string folder = "Drafts"; | |
try | |
{ | |
foreach (ExchangeMessageInfo messageInfo in client1.ListMessages(folder)) | |
client1.DeleteMessage(messageInfo.UniqueUri); | |
string subj1 = string.Format("NETWORKNET_33354 {0} {1}", "User", "User1"); | |
client1.AppendMessage(folder, new MailMessage("User1@exchange.conholdate.local", "To@aspsoe.com", subj1, "")); | |
foreach (ExchangeMessageInfo messageInfo in client2.ListMessages(folder)) | |
client2.DeleteMessage(messageInfo.UniqueUri); | |
string subj2 = string.Format("NETWORKNET_33354 {0} {1}", "User", "User2"); | |
client2.AppendMessage(folder, new MailMessage("User2@exchange.conholdate.local", "To@aspose.com", subj2, "")); | |
ExchangeMessageInfoCollection messInfoColl = client1.ListMessages(folder); | |
client1.ImpersonateUser(ItemChoice.PrimarySmtpAddress, "User2@exchange.conholdate.local"); | |
ExchangeMessageInfoCollection messInfoColl1 = client1.ListMessages(folder); | |
client1.ResetImpersonation(); | |
ExchangeMessageInfoCollection messInfoColl2 = client1.ListMessages(folder); | |
} | |
finally | |
{ | |
try | |
{ | |
foreach (ExchangeMessageInfo messageInfo in client1.ListMessages(folder)) | |
client1.DeleteMessage(messageInfo.UniqueUri); | |
foreach (ExchangeMessageInfo messageInfo in client2.ListMessages(folder)) | |
client2.DeleteMessage(messageInfo.UniqueUri); | |
} | |
catch { } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set mailboxURI, Username, password, domain information | |
string mailboxURI = "https://ex2010/ews/exchange.asmx"; | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
// Connect to the Exchange Server | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxURI, credential); | |
Console.WriteLine("Connected to Exchange server"); | |
// Get all Inbox Rules | |
InboxRule[] inboxRules = client.GetInboxRules(); | |
// Display information about each rule | |
foreach (InboxRule inboxRule in inboxRules) | |
{ | |
Console.WriteLine("Display Name: " + inboxRule.DisplayName); | |
// Check if there is a "From Address" condition | |
if (inboxRule.Conditions.FromAddresses.Count > 0) | |
{ | |
foreach (MailAddress fromAddress in inboxRule.Conditions.FromAddresses) | |
{ | |
Console.WriteLine("From: " + fromAddress.DisplayName + " - " + fromAddress.Address); | |
} | |
} | |
// Check if there is a "Subject Contains" condition | |
if (inboxRule.Conditions.ContainsSubjectStrings.Count > 0) | |
{ | |
foreach (String subject in inboxRule.Conditions.ContainsSubjectStrings) | |
{ | |
Console.WriteLine("Subject contains: " + subject); | |
} | |
} | |
// Check if there is a "Move to Folder" action | |
if (inboxRule.Actions.MoveToFolder.Length > 0) | |
{ | |
Console.WriteLine("Move message to folder: " + inboxRule.Actions.MoveToFolder); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public static void Run() | |
{ | |
// Connect to Exchange Server using ImapClient class | |
ImapClient imapClient = new ImapClient("ex07sp1", 993, "Administrator", "Evaluation1", new RemoteCertificateValidationCallback(RemoteCertificateValidationHandler)); | |
imapClient.SecurityOptions = SecurityOptions.SSLExplicit; | |
// Select the Inbox folder | |
imapClient.SelectFolder(ImapFolderInfo.InBox); | |
// Get the list of messages | |
ImapMessageInfoCollection msgCollection = imapClient.ListMessages(); | |
foreach (ImapMessageInfo msgInfo in msgCollection) | |
{ | |
Console.WriteLine(msgInfo.Subject); | |
} | |
// Disconnect from the server | |
imapClient.Dispose(); | |
} | |
// Certificate verification handler | |
private static bool RemoteCertificateValidationHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) | |
{ | |
return true; // ignore the checks and go ahead | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get folder URI | |
string strFolderURI = string.Empty; | |
strFolderURI = client.MailboxInfo.InboxUri; | |
strFolderURI = client.MailboxInfo.DeletedItemsUri; | |
strFolderURI = client.MailboxInfo.DraftsUri; | |
strFolderURI = client.MailboxInfo.SentItemsUri; | |
// Get list of messages from the specified folder | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(strFolderURI); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailAddressCollection members = client.ExpandDistributionList(new MailAddress("public.distribution.list@host.com")); | |
foreach (MailAddress member in members) | |
{ | |
Console.WriteLine(member.Address); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
static bool IsAttachmentInline(MapiAttachment attachment) | |
{ | |
foreach (MapiProperty property in attachment.ObjectData.Properties.Values) | |
{ | |
if (property.Name == "\x0003ObjInfo") | |
{ | |
ushort odtPersist1 = BitConverter.ToUInt16(property.Data, 0); | |
return (odtPersist1 & (1 << (7 - 1))) == 0; | |
} | |
} | |
return false; | |
} | |
static void SaveAttachment(MapiAttachment attachment, string fileName) | |
{ | |
foreach (MapiProperty property in attachment.ObjectData.Properties.Values) | |
{ | |
if (property.Name == "Package") | |
{ | |
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) | |
{ | |
fs.Write(property.Data, 0, property.Data.Length); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
//Create an instance of MailMessage and load an email file | |
MailMessage mailMsg = MailMessage.Load(@"EmailWithAttandEmbedded.eml"); | |
// Extract Attachments from the message | |
foreach (Attachment attachment in mailMsg.Attachments) | |
{ | |
// To display the the attachment file name and Save the attachment to disc | |
Console.WriteLine(attachment.Name); | |
attachment.Save(attachment.Name); | |
//You can also save the attachment to memory stream | |
MemoryStream memoryStream = new MemoryStream(); | |
attachment.Save(memoryStream); | |
} | |
// Extract Inline images from the message | |
foreach (LinkedResource linkResource in mailMsg.LinkedResources) | |
{ | |
Console.WriteLine(linkResource.ContentType.Name); | |
linkResource.Save(linkResource.ContentType.Name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
Contact fetchedContact = client.GetContact(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeWebServiceClient class by giving credentials | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to get Message URI | |
for (ExchangeMessageInfo msgInfo : msgCollection) | |
{ | |
String strMessageURI = msgInfo.getUniqueUri(); | |
// Now get the message details using FetchMessage() | |
MailMessage msg = client.fetchMessage(strMessageURI); | |
for (Attachment att : msg.getAttachments()) | |
{ | |
Console.WriteLine("Attachment Name: " + att.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator","username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.listMessages(client.getMailboxInfo().getInboxUri()); | |
// Loop through the collection to get Message URI | |
for (ExchangeMessageInfo msgInfo : msgCollection) | |
{ | |
String strMessageURI = msgInfo.getUniqueUri(); | |
// Now get the message details using FetchMessage() | |
MailMessage mailMessage = client.fetchMessage(strMessageURI); | |
// Display message details | |
System.out.println("Subject: " + mailMessage.getSubject()); | |
System.out.println("Number of attachments: " + mailMessage.getAttachments().size()); | |
for (Attachment att : mailMessage.getAttachments()) | |
{ | |
System.out.println("Attachment Name: " + att.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
foreach (ExchangeDistributionList distributionList in distributionLists) | |
{ | |
MailAddressCollection members = client.FetchDistributionList(distributionList); | |
foreach (MailAddress member in members) | |
{ | |
Console.WriteLine(member.Address); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
try | |
{ | |
// Connect to Exchange Server | |
const string mailboxUri = "http://exchange-server/Exchange/username"; | |
const string username = "username"; | |
const string password = "password"; | |
const string domain = "domain.com"; | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
ExchangeClient client = new ExchangeClient(mailboxUri, credential); | |
// Query building by means of ExchangeQueryBuilder class | |
ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); | |
// Set Subject and Emails that arrived today | |
builder.Subject.Contains("Newsletter"); | |
builder.InternalDate.On(DateTime.Now); | |
MailQuery query = builder.GetQuery(); | |
// Get list of messages | |
ExchangeMessageInfoCollection messages = client.ListMessages(client.MailboxInfo.InboxUri, query, false); | |
Console.WriteLine("Imap: " + messages.Count + " message(s) found."); | |
// Disconnect from IMAP | |
client.Dispose(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set mailboxURI, Username, password, domain information | |
string mailboxUri = "https://ex2010/ews/exchange.asmx"; | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
ExchangeQueryBuilder queryBuilder = null; | |
MailQuery query = null; | |
ExchangeTask fetchedTask = null; | |
ExchangeMessageInfoCollection messageInfoCol = null; | |
client.TimezoneId = "Central Europe Standard Time"; | |
Array values = Enum.GetValues(typeof(ExchangeTaskStatus)); | |
//Now retrieve the tasks with specific statuses | |
foreach (ExchangeTaskStatus status in values) | |
{ | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.TaskStatus.Equals(status); | |
query = queryBuilder.GetQuery(); | |
messageInfoCol = client.ListMessages(client.MailboxInfo.TasksUri, query); | |
fetchedTask = client.FetchTask(messageInfoCol[0].UniqueUri); | |
} | |
//retrieve all other than specified | |
foreach (ExchangeTaskStatus status in values) | |
{ | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.TaskStatus.NotEquals(status); | |
query = queryBuilder.GetQuery(); | |
messageInfoCol = client.ListMessages(client.MailboxInfo.TasksUri, query); | |
} | |
//specifying multiple criterion | |
ExchangeTaskStatus[] selectedStatuses = new ExchangeTaskStatus[] | |
{ | |
ExchangeTaskStatus.Completed, | |
ExchangeTaskStatus.InProgress | |
}; | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.TaskStatus.In(selectedStatuses); | |
query = queryBuilder.GetQuery(); | |
messageInfoCol = client.ListMessages(client.MailboxInfo.TasksUri, query); | |
queryBuilder = new ExchangeQueryBuilder(); | |
queryBuilder.TaskStatus.NotIn(selectedStatuses); | |
query = queryBuilder.GetQuery(); | |
messageInfoCol = client.ListMessages(client.MailboxInfo.TasksUri, query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeWebServiceClient client = GetAsposeEWSClient(); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Find Conversation Items in the Inbox folder | |
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri); | |
// Show all conversations | |
foreach (ExchangeConversation conversation in conversations) | |
{ | |
// Display conversation properties like Id and Topic | |
Console.WriteLine("Topic: " + conversation.ConversationTopic); | |
Console.WriteLine("Flag Status: " + conversation.FlagStatus.ToString()); | |
Console.WriteLine(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// The required extended properties must be added in order to create or read them from the Exchange Server | |
string[] extraFields = new string[] { "User Field 1", "User Field 2", "User Field 3", "User Field 4" }; | |
foreach (string extraField in extraFields) | |
client.ContactExtendedPropertiesDefinition.Add(extraField); | |
// Create a test contact on the Exchange Server | |
Contact contact = new Contact(); | |
contact.DisplayName = "EMAILNET-38433 - " + Guid.NewGuid().ToString(); | |
foreach (string extraField in extraFields) | |
contact.ExtendedProperties.Add(extraField, extraField); | |
string contactId = client.CreateContact(contact); | |
// retrieve the contact back from the server after some time | |
Thread.Sleep(5000); | |
contact = client.GetContact(contactId); | |
// Parse the extended properties of contact | |
foreach (string extraField in extraFields) | |
if (contact.ExtendedProperties.ContainsKey(extraField)) | |
Console.WriteLine(contact.ExtendedProperties[extraField].ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
List<string> ids = new List<string>(); | |
List<MailMessage> messages = new List<MailMessage>(); | |
for (int i = 0; i < 5; i++) | |
{ | |
MailMessage message = new MailMessage(user.EMail,user.EMail,"EMAILNET-35033 - " + Guid.NewGuid().ToString(),"EMAILNET-35033 Messages saved from Sent Items folder doesn't contain 'To' field"); | |
messages.Add(message); | |
string uri = client.AppendMessage(message); | |
ids.Add(uri); | |
} | |
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(ids); | |
foreach (ExchangeMessageInfo messageInfo in messageInfoCol) | |
{ | |
// Do something ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://MachineName/exchange/Username","Username", "password", "domain"); | |
// Get mailbox size, exchange mailbox info, Mailbox, Inbox folder, Sent Items folder URI , Drafts folder URI | |
Console.WriteLine("Mailbox size: " + client.GetMailboxSize() + " bytes"); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri); | |
Console.WriteLine("Inbox folder URI: " + mailboxInfo.InboxUri); | |
Console.WriteLine("Sent Items URI: " + mailboxInfo.SentItemsUri); | |
Console.WriteLine("Drafts folder URI: " + mailboxInfo.DraftsUri); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get mailbox size, exchange mailbox info, Mailbox and Inbox folder URI | |
Console.WriteLine("Mailbox size: " + client.GetMailboxSize() + " bytes"); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri); | |
Console.WriteLine("Inbox folder URI: " + mailboxInfo.InboxUri); | |
Console.WriteLine("Sent Items URI: " + mailboxInfo.SentItemsUri); | |
Console.WriteLine("Drafts folder URI: " + mailboxInfo.DraftsUri); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
Console.WriteLine("Connected to Exchange server..."); | |
// Provide mail tips options | |
MailAddressCollection addrColl = new MailAddressCollection(); | |
addrColl.Add(new MailAddress("test.exchange@ex2010.local", true)); | |
addrColl.Add(new MailAddress("invalid.recipient@ex2010.local", true)); | |
GetMailTipsOptions options = new GetMailTipsOptions("administrator@ex2010.local", addrColl, MailTipsType.All); | |
// Get Mail Tips | |
MailTips[] tips = client.GetMailTips(options); | |
// Display information about each Mail Tip | |
foreach (MailTips tip in tips) | |
{ | |
if (tip.OutOfOffice != null) | |
{ | |
Console.WriteLine("Out of office: " + tip.OutOfOffice.ReplyBody.Message); | |
} | |
if (tip.InvalidRecipient == true) | |
{ | |
Console.WriteLine("The recipient address is invalid: " + tip.RecipientAddress); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Get emails from specific domain | |
builder.From.Contains("SpecificHost.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string mailboxURI = "http://ex2003/exchange/administrator"; // WebDAV | |
string username = "administrator"; | |
string password = "pwd"; | |
string domain = "domain.local"; | |
// Credentials for connecting to Exchange Server | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
ExchangeClient client = new ExchangeClient(mailboxURI, credential); | |
// List all the contacts | |
Contact[] contacts = client.GetContacts(client.MailboxInfo.ContactsUri); | |
foreach (MapiContact contact in contacts) | |
{ | |
// Display name and email address | |
Console.WriteLine("Name: " + contact.NameInfo.DisplayName +", Email Address: " + contact.ElectronicAddresses.Email1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// List all the contacts | |
Contact[] contacts = client.GetContacts(client.MailboxInfo.ContactsUri); | |
foreach (MapiContact contact in contacts) | |
{ | |
// Display name and email address | |
Console.WriteLine("Name: " + contact.NameInfo.DisplayName +", Email Address: " + contact.ElectronicAddresses.Email1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, ICredentials); | |
UnifiedMessagingConfiguration umConf = client.GetUMConfiguration(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Register callback method for SSL validation event | |
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationHandler; | |
// This event handler is called when SSL certificate is verified | |
private static bool RemoteCertificateValidationHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) | |
{ | |
return true; //Ignore the checks and go ahead | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://MachineName/exchange/Username","username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to display the basic information | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
Console.WriteLine("Subject: " + msgInfo.Subject); | |
Console.WriteLine("From: " + msgInfo.From.ToString()); | |
Console.WriteLine("To: " + msgInfo.To.ToString()); | |
Console.WriteLine("Sent Date: " + msgInfo.Date.ToString()); | |
Console.WriteLine("Read?: " + msgInfo.IsRead.ToString()); | |
Console.WriteLine("Message ID: " + msgInfo.MessageId); | |
Console.WriteLine("Unique URI: " + msgInfo.UniqueUri); | |
Console.WriteLine("=================================="); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
public static void Run() | |
{ | |
try | |
{ | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
Console.WriteLine("Downloading all messages from Inbox...."); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri); | |
string rootUri = client.GetMailboxInfo().RootUri; | |
// List all the folders from Exchange server | |
ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(rootUri); | |
foreach (ExchangeFolderInfo folderInfo in folderInfoCollection) | |
{ | |
// Call the recursive method to read messages and get sub-folders | |
ListSubFolders(client, folderInfo); | |
} | |
Console.WriteLine("All messages downloaded."); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
private static void ListSubFolders(IEWSClient client, ExchangeFolderInfo folderInfo) | |
{ | |
// Create the folder in disk (same name as on IMAP server) | |
Console.WriteLine(folderInfo.DisplayName); | |
try | |
{ | |
// If this folder has sub-folders, call this method recursively to get messages | |
ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderInfo.Uri); | |
foreach (ExchangeFolderInfo subfolderInfo in folderInfoCollection) | |
{ | |
ListSubFolders(client, subfolderInfo); | |
} | |
} | |
catch (Exception) | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain")) | |
{ | |
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri, ExchangeListMessagesOptions.FetchAttachmentInformation, new string[] { "blablaprop" }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://MachineName/exchange/Username","username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessagesById(client.MailboxInfo.InboxUri, "23A747F0C7A5DB4BAB299C2BE2383FD556E630DD@machinename.local"); | |
// Loop through the collection to display the basic information | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
Console.WriteLine("Subject: " + msgInfo.Subject); | |
Console.WriteLine("From: " + msgInfo.From.ToString()); | |
Console.WriteLine("To: " + msgInfo.To.ToString()); | |
Console.WriteLine("Message ID: " + msgInfo.MessageId); | |
Console.WriteLine("Unique URI: " + msgInfo.UniqueUri); | |
Console.WriteLine("=================================="); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://MachineName/exchange/Username","username", "password", "domain"); | |
// Get folder URI | |
string strFolderURI = string.Empty; | |
strFolderURI = client.MailboxInfo.InboxUri; | |
strFolderURI = client.MailboxInfo.DeletedItemsUri; | |
strFolderURI = client.MailboxInfo.DraftsUri; | |
strFolderURI = client.MailboxInfo.SentItemsUri; | |
// get list of messages from the specified folder | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(strFolderURI); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set mailboxURI, Username, password, domain information | |
string mailboxUri = "https://ex2010/ews/exchange.asmx"; | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
//Listing Tasks from Server | |
client.TimezoneId = "Central Europe Standard Time"; | |
TaskCollection taskCollection = client.ListTasks(client.MailboxInfo.TasksUri); | |
//print retrieved tasks' details | |
foreach (ExchangeTask task in taskCollection) | |
{ | |
Console.WriteLine(task.TimezoneId); | |
Console.WriteLine(task.Subject); | |
Console.WriteLine(task.StartDate); | |
Console.WriteLine(task.DueDate); | |
} | |
//Listing Tasks from server based on Query - Completed and In-Progress | |
ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); | |
ExchangeTaskStatus[] selectedStatuses = new ExchangeTaskStatus[] | |
{ | |
ExchangeTaskStatus.Completed, | |
ExchangeTaskStatus.InProgress | |
}; | |
builder.TaskStatus.In(selectedStatuses); | |
MailQuery query = builder.GetQuery(); | |
taskCollection = client.ListTasks(client.MailboxInfo.TasksUri, query); | |
//print retrieved tasks' details | |
foreach (ExchangeTask task in taskCollection) | |
{ | |
Console.WriteLine(task.TimezoneId); | |
Console.WriteLine(task.Subject); | |
Console.WriteLine(task.StartDate); | |
Console.WriteLine(task.DueDate); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Base folder for reading and writing files | |
string strBaseFolder = "D:\\Data\\Aspose\\resources\\"; | |
// Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage eml = MailMessage.Load(strBaseFolder + "AnEmail.eml"); | |
// Save the Email message to disk in ASCII format and Unicode format | |
eml.Save(strBaseFolder + "AnEmail.msg", MailMessageSaveType.OutlookMessageFormatUnicode); | |
eml.Save(strBaseFolder + "AnEmail.msg", SaveOptions.DefaultMsgUnicode ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Get email delivery notifications | |
builder.MessageId.Equals("MessageID"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeWebServiceClient client = GetAsposeEWSClient(); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Find those Conversation Items in the Inbox folder which we want to move | |
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri); | |
foreach (ExchangeConversation conversation in conversations) | |
{ | |
Console.WriteLine("Topic: " + conversation.ConversationTopic); | |
// Move the conversation item based on some condition | |
if (conversation.ConversationTopic.Contains("test email") == true) | |
{ | |
client.MoveConversationItems(conversation.ConversationId, client.MailboxInfo.DeletedItemsUri); | |
Console.WriteLine("Moved the conversation item to another folder"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
// List all messages from Inbox folder | |
Console.WriteLine("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri); | |
foreach (ExchangeMessageInfo msgInfo in msgInfoColl) | |
{ | |
// Move message to "Processed" folder, after processing certain messages based on some criteria | |
if (msgInfo.Subject != null && msgInfo.Subject.ToLower().Contains("process this message") == true) | |
{ | |
client.MoveItem(mailboxInfo.DeletedItemsUri, msgInfo.UniqueUri); // EWS | |
Console.WriteLine("Message moved...." + msgInfo.Subject); | |
} | |
else | |
{ | |
// Do something else | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string mailboxURI = "https://Ex2003/exchange/administrator"; // WebDAV | |
string username = "administrator"; | |
string password = "pwd"; | |
string domain = "domain.local"; | |
Console.WriteLine("Connecting to Exchange Server...."); | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
ExchangeClient client = new ExchangeClient(mailboxURI, credential); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
// List all messages from Inbox folder | |
Console.WriteLine("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri); | |
foreach (ExchangeMessageInfo msgInfo in msgInfoColl) | |
{ | |
// Nove message to "Processed" folder, after processing certain messages based on some criteria | |
if (msgInfo.Subject != null && | |
msgInfo.Subject.ToLower().Contains("process this message") == true) | |
{ | |
client.MoveItems(msgInfo.UniqueUri, client.MailboxInfo.RootUri + "/Processed/" + msgInfo.Subject); | |
Console.WriteLine("Message moved...." + msgInfo.Subject); | |
} | |
else | |
{ | |
// Do something else | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (IEWSClient client = EWSClient.GetEWSClient("exchange.domain.com", "username", "password")) | |
{ | |
try | |
{ | |
Appointment[] appts = client.ListAppointments(); | |
Console.WriteLine(appts.Length); | |
DateTime date = DateTime.Now; | |
DateTime startTime = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0); | |
DateTime endTime = startTime.AddHours(1); | |
int appNumber = 10; | |
Dictionary<string, Appointment> appointmentsDict = new Dictionary<string, Appointment>(); | |
for (int i = 0; i < appNumber; i++) | |
{ | |
startTime = startTime.AddHours(1); | |
endTime = endTime.AddHours(1); | |
string timeZone = "America/New_York"; | |
Appointment appointment = new Appointment("Room 112",startTime,endTime,"from@domain.com","to@domain.com"); | |
appointment.SetTimeZone(timeZone); | |
appointment.Summary = "NETWORKNET-35157_3 - " + Guid.NewGuid().ToString(); | |
appointment.Description = "EMAILNET-35157 Move paging parameters to separate class"; | |
string uid = client.CreateAppointment(appointment); | |
appointmentsDict.Add(uid, appointment); | |
} | |
AppointmentCollection totalAppointmentCol = client.ListAppointments(); | |
///// LISTING APPOINTMENTS WITH PAGING SUPPORT /////// | |
int itemsPerPage = 2; | |
List<AppointmentPageInfo> pages = new List<AppointmentPageInfo>(); | |
AppointmentPageInfo pagedAppointmentCol = client.ListAppointmentsByPage(itemsPerPage); | |
Console.WriteLine(pagedAppointmentCol.Items.Count); | |
pages.Add(pagedAppointmentCol); | |
while (!pagedAppointmentCol.LastPage) | |
{ | |
pagedAppointmentCol = client.ListAppointmentsByPage(itemsPerPage, pagedAppointmentCol.PageOffset + 1); | |
pages.Add(pagedAppointmentCol); | |
} | |
int retrievedItems = 0; | |
foreach (AppointmentPageInfo folderCol in pages) | |
retrievedItems += folderCol.Items.Count; | |
} | |
finally | |
{} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (IEWSClient client = EWSClient.GetEWSClient("exchange.domain.com", "username", "password")) | |
{ | |
int itemsPerPage = 5; | |
ExchangeFolderInfoCollection totalFoldersCollection = client.ListSubFolders(client.MailboxInfo.RootUri); | |
Console.WriteLine(totalFoldersCollection.Count); | |
//////////////////// RETREIVING INFORMATION USING PAGING SUPPORT ////////////////////////////////// | |
List<ExchangeFolderPageInfo> pages = new List<ExchangeFolderPageInfo>(); | |
ExchangeFolderPageInfo pagedFoldersCollection = client.ListSubFoldersByPage(client.MailboxInfo.RootUri, itemsPerPage); | |
Console.WriteLine(pagedFoldersCollection.TotalCount); | |
pages.Add(pagedFoldersCollection); | |
while (!pagedFoldersCollection.LastPage) | |
{ | |
pagedFoldersCollection = client.ListSubFoldersByPage(client.MailboxInfo.RootUri, itemsPerPage, pagedFoldersCollection.PageOffset + 1); | |
pages.Add(pagedFoldersCollection); | |
} | |
int retrievedFolders = 0; | |
foreach (ExchangeFolderPageInfo pageCol in pages) | |
retrievedFolders += pageCol.Items.Count; | |
// Verify the total count of folders | |
Console.WriteLine(retrievedFolders); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (IEWSClient client = EWSClient.GetEWSClient("exchange.domain.com", "username", "password")) | |
{ | |
try | |
{ | |
// Create some test messages to be added to server for retrieval later | |
int messagesNum = 12; | |
int itemsPerPage = 5; | |
MailMessage message = null; | |
for (int i = 0; i < messagesNum; i++) | |
{ | |
message = new MailMessage("from@domain.com","to@domain.com","EMAILNET-35157_1 - " + Guid.NewGuid().ToString(),"EMAILNET-35157 Move paging parameters to separate class"); | |
client.AppendMessage(client.MailboxInfo.InboxUri, message); | |
} | |
// Verfiy that the messages have been added to the server | |
ExchangeMessageInfoCollection totalMessageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
Console.WriteLine(totalMessageInfoCol.Count); | |
////////////////// RETREIVING THE MESSAGES USING PAGING SUPPORT //////////////////////////////////// | |
List<ExchangeMessagePageInfo> pages = new List<ExchangeMessagePageInfo>(); | |
ExchangeMessagePageInfo pageInfo = client.ListMessagesByPage(client.MailboxInfo.InboxUri, itemsPerPage); | |
// Total Pages Count | |
Console.WriteLine(pageInfo.TotalCount); | |
pages.Add(pageInfo); | |
while (!pageInfo.LastPage) | |
{ | |
pageInfo = client.ListMessagesByPage(client.MailboxInfo.InboxUri, itemsPerPage, pageInfo.PageOffset + 1); | |
pages.Add(pageInfo); | |
} | |
int retrievedItems = 0; | |
foreach (ExchangeMessagePageInfo pageCol in pages) | |
retrievedItems += pageCol.Items.Count; | |
// Verify total message count using paging | |
Console.WriteLine(retrievedItems); | |
} | |
finally | |
{} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeWebServiceClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to display the basic information | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
Console.WriteLine("Subject: " + msgInfo.Subject); | |
Console.WriteLine("From: " + msgInfo.From.ToString()); | |
Console.WriteLine("To: " + msgInfo.To.ToString()); | |
Console.WriteLine("Message Size: " + msgInfo.Size); | |
Console.WriteLine("=================================="); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create Exchange task object | |
ExchangeTask task = new ExchangeTask(); | |
// Set task subject and status to In progress | |
task.Subject = "New-Test"; | |
task.Status = ExchangeTaskStatus.InProgress; | |
client.CreateTask(client.MailboxInfo.TasksUri, task); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeWebServiceClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "username", "password"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to display the basic information | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
Console.WriteLine("Subject: " + msgInfo.Subject); | |
Console.WriteLine("From: " + msgInfo.From.ToString()); | |
Console.WriteLine("To: " + msgInfo.To.ToString()); | |
Console.WriteLine("Message ID: " + msgInfo.MessageId); | |
Console.WriteLine("Unique URI: " + msgInfo.UniqueUri); | |
Console.WriteLine("=================================="); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get Exchange mailbox info of other email account | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(”otherUser@domain.com”); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username","Username", "password", "domain"); | |
// Get Exchange mailbox info of other email account | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(”otherUser@domain.com”); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MapiMessage message = MapiMessage.FromFile(fileName); | |
// This method can be useful when except voting buttons it is necessary to get other parameters (ex. a category) | |
options = FollowUpManager.GetOptions(message); | |
// Voting buttons will be introduced as a string with semi-column as a separator | |
string votingButtons = options.VotingButtons; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = GetAsposeEWSClient(); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Get the User Configuration for Inbox folder | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri); | |
UserConfiguration userConfig = client.GetUserConfiguration(userConfigName); | |
Console.WriteLine("Configuration Id: " + userConfig.Id); | |
Console.WriteLine("Configuration Name: " + userConfig.UserConfigurationName.Name); | |
Console.WriteLine("Key value pairs:"); | |
foreach (string key in userConfig.Dictionary.Keys) | |
{ | |
Console.WriteLine(key + ": " + userConfig.Dictionary[key].ToString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
var appointment = Appointment.Load(fileName); | |
var outlookMsg = new MailMessage(); | |
outlookMsg.AddAlternateView(appointment.RequestApointment()); | |
MhtSaveOptions opt = SaveOptions.DefaultMhtml; | |
opt.MhtFormatOptions = opt.MhtFormatOptions | MhtFormatOptions.RenderCalendarEvent; | |
outlookMsg.Save(mhtfileName, opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// List all the contacts | |
Contact[] contacts = client.ResolveContacts("Changed Name", ExchangeListContactsOptions.FetchAttachmentAndFullPhotoInformation); | |
foreach (MapiContact contact in contacts) | |
{ | |
// Display name and email address | |
Console.WriteLine("Name: " + contact.NameInfo.DisplayName +", Email Address: " + contact.ElectronicAddresses.Email1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (ImapClient client = new ImapClient("host.domain.com", "username", "password")) | |
{ | |
MailMessage message = new MailMessage("from@domain.com", "to@doman.com", "EMAILNET-38466 - " + Guid.NewGuid().ToString(), "EMAILNET-38466 Add extra parameters for UID FETCH command"); | |
// append the message to the server | |
string uid = client.AppendMessage(message); | |
// wait for the message to be appended | |
Thread.Sleep(5000); | |
// Define properties to be fetched from server along with the message | |
string[] messageExtraFields = new string[] { "X-GM-MSGID", "X-GM-THRID" }; | |
// retreive the message summary information using it's UID | |
ImapMessageInfo messageInfoUID = client.ListMessage(uid, messageExtraFields); | |
// retreive the message summary information using it's sequence number | |
ImapMessageInfo messageInfoSeqNum = client.ListMessage(1, messageExtraFields); | |
// List messages in general from the server based on the defined properties | |
ImapMessageInfoCollection messageInfoCol = client.ListMessages(messageExtraFields); | |
ImapMessageInfo messageInfoFromList = messageInfoCol[0]; | |
// verify that the parameters are fetched in the summary information | |
foreach (string paramName in messageExtraFields) | |
{ | |
Console.WriteLine(messageInfoFromList.ExtraParameters.ContainsKey(paramName)); | |
Console.WriteLine(messageInfoUID.ExtraParameters.ContainsKey(paramName)); | |
Console.WriteLine(messageInfoSeqNum.ExtraParameters.ContainsKey(paramName)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string folderName = "DesiredFolderName"; | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeFolderInfoCollection folders = client.ListPublicFolders(); | |
ExchangeFolderPermissionCollection permissions = new ExchangeFolderPermissionCollection(); | |
ExchangeFolderInfo publicFolder = null; | |
try | |
{ | |
foreach (ExchangeFolderInfo folderInfo in folders) | |
if (folderInfo.DisplayName.Equals(folderName)) | |
publicFolder = folderInfo; | |
if (publicFolder == null) | |
Console.WriteLine("public folder was not created in the root public folder"); | |
ExchangePermissionCollection folderPermissionCol = client.GetFolderPermissions(publicFolder.Uri); | |
foreach (ExchangeBasePermission perm in folderPermissionCol) | |
{ | |
ExchangeFolderPermission permission = perm as ExchangeFolderPermission; | |
if (permission == null) | |
Console.WriteLine("Permission is null."); | |
else | |
{ | |
Console.WriteLine("User's primary smtp address: {0}", permission.UserInfo.PrimarySmtpAddress); | |
Console.WriteLine("User can create Items: {0}", permission.CanCreateItems.ToString()); | |
Console.WriteLine("User can delete Items: {0}", permission.DeleteItems.ToString()); | |
Console.WriteLine("Is Folder Visible: {0}", permission.IsFolderVisible.ToString()); | |
Console.WriteLine("Is User owner of this folder: {0}", permission.IsFolderOwner.ToString()); | |
Console.WriteLine("User can read items: {0}", permission.ReadItems.ToString()); | |
} | |
} | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
// Get the Permissions for the Contacts and Calendar Folder | |
ExchangePermissionCollection contactsPermissionCol = client.GetFolderPermissions(mailboxInfo.ContactsUri); | |
ExchangePermissionCollection calendarPermissionCol = client.GetFolderPermissions(mailboxInfo.CalendarUri); | |
} | |
finally | |
{ | |
// Do the needfull | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeTask task = new ExchangeTask(); | |
task.Subject = "EMAILNET-34759 - " + Guid.NewGuid(); | |
task.Status = ExchangeTaskStatus.InProgress; | |
task.StartDate = new DateTime(2028, 10, 6, 12, 30, 00); | |
task.DueDate = task.StartDate.AddDays(3); | |
task.Save(OutFileName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Base folder for reading and writing files | |
string strBaseFolder = "D:\\Data\\Aspose\\resources\\"; | |
// Initialize and Load an existing EML file by specifying the MessageFormat | |
MailMessage eml = MailMessage.Load(strBaseFolder + "AnEmail.eml"); | |
eml.Save(strBaseFolder + "AnEmail.mthml", SaveOptions.DefaultMHtml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailMessage msg = MailMessage.Load(fileName); | |
msg.Save(outFileName, SaveOptions.DefaultHtml); | |
or | |
MailMessage eml = MailMessage.Load(fileName); | |
HtmlSaveOptions options = SaveOptions.DefaultHtml; | |
options.EmbedResources = false; | |
options.HtmlFormatOptions = HtmlFormatOptions.WriteHeader | HtmlFormatOptions.WriteCompleteEmailAddress; //save the message headers to output HTML using the formatting options | |
eml.Save(outFileName, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://Servername/exchange/username", "username", "password", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to get Message URI | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMessageURI = msgInfo.UniqueUri; | |
// Now save the message in disk | |
client.SaveMessage(strMessageURI, dataDir + msgInfo.MessageId + "_out.eml"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to get Message URI | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMessageURI = msgInfo.UniqueUri; | |
// Now get the message details using FetchMessage() and Save message as Msg | |
MailMessage message = client.FetchMessage(strMessageURI); | |
message.Save(@"e:\data\aspose\temp\" + msgInfo.MessageId + ".msg", MessageFormat.Msg); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("http://ex07sp1/exchange/Administrator","user", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to get Message URI | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMessageURI = msgInfo.UniqueUri; | |
// Now get the message details using FetchMessage() and Save message as msg | |
MailMessage message = client.FetchMessage(strMessageURI); | |
message.Save(@"e:\data\aspose\temp\" + msgInfo.MessageId + ".msg", MessageFormat.Msg); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://Ex07sp1/exchange/Administrator", "user", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to get Message URI | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMessageURI = msgInfo.UniqueUri; | |
MemoryStream stream = new MemoryStream(); | |
client.SaveMessage(strMessageURI, dataDir + stream); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string datadir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to get Message URI | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMessageURI = msgInfo.UniqueUri; | |
// Now save the message in memory stream | |
MemoryStream stream = new MemoryStream(); | |
client.SaveMessage(strMessageURI, datadir + stream); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Call ListMessages method to list messages info from Inbox | |
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); | |
// Loop through the collection to get Message URI | |
foreach (ExchangeMessageInfo msgInfo in msgCollection) | |
{ | |
string strMessageURI = msgInfo.UniqueUri; | |
// Now save the message in disk | |
client.SaveMessage(strMessageURI, dataDir + msgInfo.MessageId + "out.eml"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Email(); | |
MailMessage eml = MailMessage.Load(dataDir + "test.eml"); | |
// Save as msg with preserved dates | |
MsgSaveOptions msgSaveOptions = new MsgSaveOptions(MailMessageSaveType.OutlookMessageFormatUnicode) | |
{ | |
PreserveOriginalDates = true | |
}; | |
eml.Save(Path.Combine(directoryPath, "outTest.msg"), msgSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Get the list of messages | |
ImapMessageInfoCollection msgCollection = imapClient.ListMessages(); | |
foreach (ImapMessageInfo msgInfo in msgCollection) | |
{ | |
// Fetch the message from inbox using its SequenceNumber from msgInfo | |
MailMessage message = imapClient.FetchMessage(msgInfo.SequenceNumber); | |
// Save the message to disc now | |
msg.Save(msgInfo.SequenceNumber + ".msg", MailMessageSaveType.OutlookMessageFormat); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using(IEWSClientclient=EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx","your.username","your.Password)) | |
{ | |
try | |
{ | |
// Create an appointment that will be added to secondary calendarfolder | |
DateTimedate=DateTime.Now; | |
DateTimestartTime=newDateTime(date.Year,date.Month,date.Day,date.Hour,0,0); | |
DateTimeendTime=startTime.AddHours(1); | |
stringtimeZone="America/New_York"; | |
Appointment[]listAppointments; | |
Appointmentappointment=newAppointment("Room121",startTime,endTime,"from@domain.com","attendee@domain.com"); | |
appointment.SetTimeZone(timeZone); | |
appointment.Summary="EMAILNET-35198-"+Guid.NewGuid().ToString(); | |
appointment.Description="EMAILNET-35198AbilitytoaddeventtoSecondaryCalendarofOffice365"; | |
// Verify that the new folder has been created | |
ExchangeFolderInfoCollectioncalendarSubFolders=client.ListSubFolders(client.MailboxInfo.CalendarUri); | |
stringgetfolderName; | |
stringsetFolderName="NewCalendar"; | |
boolalreadyExits=false; | |
// Verify that the new folder has been created already exits or not | |
for(inti=0;i<calendarSubFolders.Count;i++) | |
{ | |
getfolderName=calendarSubFolders[i].DisplayName; | |
if(getfolderName.Equals(setFolderName)) | |
{ | |
alreadyExits=true; | |
} | |
} | |
if(alreadyExits) | |
{ | |
Console.WriteLine("FolderAlreadyExists"); | |
} | |
else | |
{ | |
// Create newcalendar folder | |
client.CreateFolder(client.MailboxInfo.CalendarUri,setFolderName,null,"IPF.Appointment"); | |
Console.WriteLine(calendarSubFolders.Count); | |
// Getthe created folderURI | |
stringnewCalendarFolderUri=calendarSubFolders[0].Uri; | |
// Create, update Appointment | |
client.CreateAppointment(appointment,newCalendarFolderUri); | |
appointment.Location="Room122"; | |
client.UpdateAppointment(appointment,newCalendarFolderUri); | |
listAppointments=client.ListAppointments(newCalendarFolderUri); | |
listAppointments=client.ListAppointments(client.MailboxInfo.CalendarUri); | |
client.CancelAppointment(appointment,newCalendarFolderUri); | |
listAppointments=client.ListAppointments(newCalendarFolderUri); | |
client.CurrentCalendarFolderUri=newCalendarFolderUri; | |
client.CreateAppointment(appointment); | |
appointment.Location="Room122"; | |
client.UpdateAppointment(appointment); | |
listAppointments=client.ListAppointments(); | |
listAppointments=client.ListAppointments(client.MailboxInfo.CalendarUri); | |
client.CancelAppointment(appointment); | |
listAppointments=client.ListAppointments(); | |
} | |
} | |
finally | |
{} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain")) | |
{ | |
// delegate calendar access permission | |
ExchangeDelegateUser delegateUser = new ExchangeDelegateUser("sharingfrom@domain.com", ExchangeDelegateFolderPermissionLevel.NotSpecified); | |
delegateUser.FolderPermissions.CalendarFolderPermissionLevel = ExchangeDelegateFolderPermissionLevel.Reviewer; | |
client.DelegateAccess(delegateUser, "sharingfrom@domain.com"); | |
// Create invitation and send invitation | |
MapiMessage mapiMessage = client.CreateCalendarSharingInvitationMessage("sharingfrom@domain.com"); | |
MailMessageInterpretor messageInterpretor = MailMessageInterpretorFactory.Instance.GetIntepretor(mapiMessage.MessageClass); | |
MailMessage mailMessage = messageInterpretor.InterpretAsTnef(mapiMessage); | |
client.Send(mailMessage); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
ExchangeClient client = new ExchangeClient("https://MachineName/exchange/username", "username", "password", "domain"); | |
// Create instance of type MailMessage | |
MailMessage msg = new MailMessage(); | |
msg.From = "sender@domain.com"; | |
msg.To = "recipient@ domain.com "; | |
msg.Subject = "Sending message from exchange server"; | |
msg.HtmlBody = "<h3>sending message from exchange server</h3>"; | |
// Send the message | |
client.Send(msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create instance of type MailMessage | |
MailMessage msg = new MailMessage(); | |
msg.From = "sender@domain.com"; | |
msg.To = "recipient@ domain.com "; | |
msg.Subject = "Sending message from exchange server"; | |
msg.HtmlBody = "<h3>sending message from exchange server</h3>"; | |
// Send the message | |
client.Send(msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
string dstEmail = dataDir + "Message.eml"; | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// load task from .eml file | |
EmlLoadOptions loadOptions = new EmlLoadOptions(); | |
loadOptions.PrefferedTextEncoding = Encoding.UTF8; | |
loadOptions.PreserveTnefAttachments = true; | |
// load task from .msg file | |
MailMessage eml = MailMessage.Load(dstEmail, loadOptions); | |
eml.From = "firstname.lastname@domain.com"; | |
eml.To.Clear(); | |
eml.To.Add(new MailAddress("firstname.lastname@domain.com")); | |
client.Send(eml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
try | |
{ | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// create the meeting request | |
Appointment app = new Appointment("meeting request", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1.5), "administrator@test.com", "bob@test.com"); | |
app.Summary = "meeting request summary"; | |
app.Description = "description"; | |
// set recurrence pattern for this appointment | |
RecurrencePattern pattern = new DailyRecurrencePattern(DateTime.Now.AddDays(5)); | |
app.RecurrencePattern = pattern; | |
// create the message and set the meeting request | |
MailMessage msg = new MailMessage(); | |
msg.From = "administrator@test.com"; | |
msg.To = "bob@test.com"; | |
msg.IsBodyHtml = true; | |
msg.HtmlBody = "<h3>HTML Heading</h3><p>Email Message detail</p>"; | |
msg.Subject = "meeting request"; | |
msg.AddAlternateView(app.RequestApointment(0)); | |
// send the appointment | |
client.Send(msg); | |
Console.WriteLine("Appointment request sent"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
try | |
{ | |
string mailboxUri = @"https://ex07sp1/exchange/administrator"; // WebDAV | |
string domain = @"litwareinc.com"; | |
string username = @"administrator"; | |
string password = @"Evaluation1"; | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
Console.WriteLine("Connecting to Exchange server....."); | |
// Connect to Exchange Server | |
ExchangeClient client = new ExchangeClient(mailboxUri, credential); // WebDAV | |
// Create the meeting request | |
Appointment app = new Appointment("meeting request", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1.5), "administrator@" + domain, "bob@" + domain); | |
app.Summary = "meeting request summary"; | |
app.Description = "description"; | |
// Create the message and set the meeting request | |
MailMessage msg = new MailMessage(); | |
msg.From = "administrator@" + domain; | |
msg.To = "bob@" + domain; | |
msg.IsBodyHtml = true; | |
msg.HtmlBody = "<h3>HTML Heading</h3><p>Email Message detail</p>"; | |
msg.Subject = "meeting request"; | |
msg.AddAlternateView(app.RequestApointment(0)); | |
// Send the appointment | |
client.Send(msg); | |
Console.WriteLine("Appointment request sent"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
MailAddress distributionListAddress = distributionLists[0].ToMailAddress(); | |
MailMessage message = new MailMessage(new MailAddress("from@host.com"), distributionListAddress); | |
message.Subject = "sendToPrivateDistributionList"; | |
client.Send(message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MsgLoadOptions options = new MsgLoadOptions(); | |
options.PreserveTnefAttachments = true; | |
// load task from .msg file | |
MailMessage eml = MailMessage.Load(dataDir + "task.msg", options); | |
eml.From = "firstname.lastname@domain.com"; | |
eml.To.Clear(); | |
eml.To.Add(new MailAddress("firstname.lastname@domain.com")); | |
client.Send(eml); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
private static IEWSClient GetAsposeEWSClient() | |
{ | |
// Exchange Server 2010 web service URL | |
string mailboxURI = "https://ex2010/ews/exchange.asmx"; | |
// Specify Username, password, domain information | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
// Connect to the Exchange Server | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxURI, credential); | |
// Return the instance of IEWSClient class | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
private static IEWSClient GetAsposeEWSClient() | |
{ | |
const string mailboxUri = "https://exchnage/ews/exchange.asmx"; | |
const string domain = @""; | |
const string username = @"username@ASE305.onmicrosoft.com"; | |
const string password = @"password"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Get emails from specific sender | |
builder.From.Contains("saqib.razzaq@127.0.0.1"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.Bcc.Add("CC1@receiver.com"); | |
message.Bcc.Add("CC2@receiver.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
message.CC.Add("CC1@receiver.com"); | |
message.CC.Add("CC2@receiver.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
//Create an Instance of MailMessage class | |
MailMessage message = new MailMessage(); | |
//Specify the recipients mail addresses | |
message.To.Add("receiver1@receiver.com"); | |
message.To.Add("receiver2@receiver.com"); | |
message.To.Add("receiver3@receiver.com"); | |
message.To.Add("receiver4@receiver.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
client.TimezoneId = "Central Europe Standard Time"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MailMessage message1 = new MailMessage("user@domain.com", "user@domain.com", "EMAILNET-34738 - " + Guid.NewGuid().ToString(), | |
"EMAILNET-34738 Sync Folder Items"); | |
client.Send(message1); | |
MailMessage message2 = new MailMessage("user@domain.com", "user@domain.com", "EMAILNET-34738 - " + Guid.NewGuid().ToString(), | |
"EMAILNET-34738 Sync Folder Items"); | |
client.Send(message2); | |
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
SyncFolderResult result = client.SyncFolder(client.MailboxInfo.InboxUri,null); | |
Console.WriteLine(result.NewItems.Count); | |
Console.WriteLine(result.ChangedItems.Count); | |
Console.WriteLine(result.ReadFlagChanged.Count); | |
Console.WriteLine(result.DeletedItems.Length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, ICredentials); | |
// List all the contacts and Loop through all contacts | |
Contact[] contacts = client.GetContacts(client.MailboxInfo.ContactsUri); | |
Contact contact = contacts[0]; | |
Console.WriteLine("Name: " + contact.DisplayName); | |
contact.DisplayName = "David Ch"; | |
client.UpdateContact(contact); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set mailboxURI, Username, password, domain information | |
string mailboxURI = "https://ex2010/ews/exchange.asmx"; | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
// Connect to the Exchange Server | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxURI, credential); | |
Console.WriteLine("Connected to Exchange server"); | |
// Get all Inbox Rules | |
InboxRule[] inboxRules = client.GetInboxRules(); | |
// Loop through each rule | |
foreach (InboxRule inboxRule in inboxRules) | |
{ | |
Console.WriteLine("Display Name: " + inboxRule.DisplayName); | |
if (inboxRule.DisplayName == "Message from client ABC") | |
{ | |
Console.WriteLine("Updating the rule...."); | |
inboxRule.Conditions.FromAddresses[0] = new MailAddress("administrator@ex2010.local", true); | |
client.UpdateInboxRule(inboxRule); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create and initialize credentials | |
var credentials = new NetworkCredential("username", "12345"); | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks info collection from exchange | |
ExchangeMessageInfoCollection tasks = client.ListMessages(client.MailboxInfo.TasksUri); | |
foreach (ExchangeMessageInfo info in tasks) | |
{ | |
// Fetch task from exchange using current task info and Update the task status to NotStarted | |
ExchangeTask task = client.FetchTask(info.UniqueUri); | |
task.Status = ExchangeTaskStatus.NotStarted; | |
// Set the task due date, task priority and Update task on exchange | |
task.DueDate = new DateTime(2013, 2, 26); | |
task.Priority = MailPriority.Low; | |
client.UpdateTask(task); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
// Create the User Configuration for Inbox folder | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri); | |
UserConfiguration userConfig = client.GetUserConfiguration(userConfigName); | |
userConfig.Id = null; | |
// Update User Configuration | |
userConfig.Dictionary["key1"] = "new-value1"; | |
client.UpdateUserConfiguration(userConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (IEWSClient client = EWSClient.GetEWSClient("https://exchange.office365.com/ews/exchange.asmx", "username", "password")) | |
{ | |
DateTime startTime = DateTime.Now; | |
TimeSpan maxRestoreTime = TimeSpan.FromSeconds(15); | |
int processedItems = 0; | |
BeforeItemCallback callback = delegate | |
{ | |
if (DateTime.Now >= startTime.Add(maxRestoreTime)) | |
{ | |
throw new CustomAbortRestoreException(); | |
} | |
processedItems++; | |
}; | |
try | |
{ | |
//create a test pst and add some test messages to it | |
var pst = PersonalStorage.Create(new MemoryStream(), FileFormatVersion.Unicode); | |
var folder = pst.RootFolder.AddSubFolder("My test folder"); | |
for (int i = 0; i < 20; i++) | |
{ | |
var message = new MapiMessage("from@gmail.com", "to@gmail.com", "subj", new string('a', 10000)); | |
folder.AddMessage(message); | |
} | |
//now restore the PST with callback | |
client.Restore(pst, new Aspose.Email.Clients.Exchange.WebService.RestoreSettings | |
{ | |
BeforeItemCallback = callback | |
}); | |
Console.WriteLine("Success!"); | |
} | |
catch (CustomAbortRestoreException) | |
{ | |
Console.WriteLine($"Timeout! {processedItems}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get Exchange mailbox info of other email account | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo("otherUser@domain.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create ExchangeMailboxInfo, ExchangeMessageInfoCollection instance | |
ExchangeMailboxInfo mailbox = client.GetMailboxInfo(); | |
ExchangeMessageInfoCollection messages = null; | |
ExchangeFolderInfo subfolderInfo = new ExchangeFolderInfo(); | |
// Check if specified custom folder exisits and Get all the messages info from the target Uri | |
client.FolderExists(mailbox.InboxUri, "TestInbox", out subfolderInfo); | |
//if custom folder exists | |
if (subfolderInfo != null) | |
{ | |
messages = client.ListMessages(subfolderInfo.Uri); | |
// Parse all the messages info collection | |
foreach (ExchangeMessageInfo info in messages) | |
{ | |
string strMessageURI = info.UniqueUri; | |
// now get the message details using FetchMessage() | |
MailMessage msg = client.FetchMessage(strMessageURI); | |
Console.WriteLine("Subject: " + msg.Subject); | |
} | |
} | |
else | |
{ | |
Console.WriteLine("No folder with this name found."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set mailboxURI, Username, password, domain information | |
string mailboxUri = "https://ex2010/ews/exchange.asmx"; | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
//Create New Contact | |
Contact contact = new Contact(); | |
//Set general info | |
contact.Gender = Gender.Male; | |
contact.DisplayName = "Frank Lin"; | |
contact.CompanyName = "ABC Co."; | |
contact.JobTitle = "Executive Manager"; | |
//Add Phone numbers | |
contact.PhoneNumbers.Add(new PhoneNumber { Number = "123456789", Category = PhoneNumberCategory.Home }); | |
//contact's associated persons | |
contact.AssociatedPersons.Add(new AssociatedPerson { Name = "Catherine", Category = AssociatedPersonCategory.Spouse }); | |
contact.AssociatedPersons.Add(new AssociatedPerson { Name = "Bob", Category = AssociatedPersonCategory.Child }); | |
contact.AssociatedPersons.Add(new AssociatedPerson { Name = "Merry", Category = AssociatedPersonCategory.Sister }); | |
//URLs | |
contact.Urls.Add(new Url { Href = "www.blog.com", Category = UrlCategory.Blog }); | |
contact.Urls.Add(new Url { Href = "www.homepage.com", Category = UrlCategory.HomePage }); | |
//Set contact's Email address | |
contact.EmailAddresses.Add(new EmailAddress { Address = "Frank.Lin@Abc.com", DisplayName = "Frank Lin", Category = EmailAddressCategory.Email1 }); | |
try | |
{ | |
client.CreateContact(contact); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
using (IEWSClient client = EWSClient.GetEWSClient("exchange.domain.com/ews/Exchange.asmx", "username", "password", "")) | |
{ | |
client.AddHeader("X-AnchorMailbox", "username@domain.com"); | |
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.Add("address4@host.com"); | |
newMembers.Add("address5@host.com"); | |
client.AddToDistributionList(distributionLists[0], newMembers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.Id = "list's id"; | |
distributionList.ChangeKey = "list's change key"; | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.Add("address6@host.com"); | |
client.AddToDistributionList(distributionList, newMembers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string email = "asposeemail.test3@aspose.com"; | |
string password = "Aspose@2017"; | |
AutodiscoverService svc = new AutodiscoverService(); | |
svc.Credentials = new NetworkCredential(email, password); | |
IDictionary<UserSettingName, object> userSettings = svc.GetUserSettings(email, UserSettingName.ExternalEwsUrl).Settings; | |
string ewsUrl = (string)userSettings[UserSettingName.ExternalEwsUrl]; | |
Console.WriteLine("Auto discovered EWS Url: " + ewsUrl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Query building by means of ExchangeQueryBuilder class | |
ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); | |
builder.Subject.Contains("Newsletter", true); | |
builder.InternalDate.On(DateTime.Now); | |
MailQuery query = builder.GetQuery(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Connect to Exchange Server using ImapClient class | |
ImapClient imapClient = new ImapClient("ex07sp1", "Administrator", "Evaluation1"); | |
imapClient.SecurityOptions = SecurityOptions.Auto; | |
// Select the Inbox folder | |
imapClient.SelectFolder(ImapFolderInfo.InBox); | |
// Get the list of messages | |
ImapMessageInfoCollection msgCollection = imapClient.ListMessages(); | |
foreach (ImapMessageInfo msgInfo in msgCollection) | |
{ | |
Console.WriteLine(msgInfo.Subject); | |
} | |
// Disconnect from the server | |
imapClient.Dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
private static IEWSClient GetExchangeEWSClient() | |
{ | |
const string mailboxUri = "https://outlook.office365.com/ews/exchange.asmx"; | |
const string domain = @""; | |
const string username = @"username@ASE305.onmicrosoft.com"; | |
const string password = @"password"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
return client; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Find those Conversation Items in the Inbox folder which we want to copy | |
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri); | |
foreach (ExchangeConversation conversation in conversations) | |
{ | |
Console.WriteLine("Topic: " + conversation.ConversationTopic); | |
// Copy the conversation item based on some condition | |
if (conversation.ConversationTopic.Contains("test email") == true) | |
{ | |
client.CopyConversationItems(conversation.ConversationId, client.MailboxInfo.DeletedItemsUri); | |
Console.WriteLine("Copied the conversation item to another folder"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
try | |
{ | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MailMessage message = new MailMessage("from@domain.com", "to@domain.com", "EMAILNET-34997 - " + Guid.NewGuid().ToString(), "EMAILNET-34997 Exchange: Copy a message and get reference to the new Copy item"); | |
string messageUri = client.AppendMessage(message); | |
string newMessageUri = client.CopyItem(messageUri, client.MailboxInfo.DeletedItemsUri); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string address = "firstname.lastname@aspose.com"; | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MailMessage message = CreateTestMessage(address); | |
// Set FollowUpOptions Buttons | |
FollowUpOptions options = new FollowUpOptions(); | |
options.VotingButtons = "Yes;No;Maybe;Exactly!"; | |
client.Send(message, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
private static MailMessage CreateTestMessage(string address) | |
{ | |
MailMessage eml = new MailMessage( | |
address, | |
address, | |
"Flagged message", | |
"Make it nice and short, but descriptive. The description may appear in search engines' search results pages..."); | |
return eml; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
string inbox = client.MailboxInfo.InboxUri; | |
string folderName1 = "EMAILNET-35054"; | |
string subFolderName0 = "2015"; | |
string folderName2 = folderName1 + "/" + subFolderName0; | |
string folderName3 = folderName1 + " / 2015"; | |
ExchangeFolderInfo rootFolderInfo = null; | |
ExchangeFolderInfo folderInfo = null; | |
try | |
{ | |
client.UseSlashAsFolderSeparator = true; | |
client.CreateFolder(client.MailboxInfo.InboxUri, folderName1); | |
client.CreateFolder(client.MailboxInfo.InboxUri, folderName2); | |
} | |
finally | |
{ | |
if (client.FolderExists(inbox, folderName1, out rootFolderInfo)) | |
{ | |
if (client.FolderExists(inbox, folderName2, out folderInfo)) | |
client.DeleteFolder(folderInfo.Uri, true); | |
client.DeleteFolder(rootFolderInfo.Uri, true); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set Exchange Server web service URL, Username, password, domain information | |
string mailboxURI = "https://ex2010/ews/exchange.asmx"; | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
// Connect to the Exchange Server | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxURI, credential); | |
Console.WriteLine("Connected to Exchange server"); | |
InboxRule rule = new InboxRule(); | |
rule.DisplayName = "Message from client ABC"; | |
// Add conditions | |
RulePredicates newRules = new RulePredicates(); | |
// Set Subject contains string "ABC" and Add the conditions | |
newRules.ContainsSubjectStrings.Add("ABC"); | |
newRules.FromAddresses.Add(new MailAddress("administrator@ex2010.local", true)); | |
rule.Conditions = newRules; | |
// Add Actions and Move the message to a folder | |
RuleActions newActions = new RuleActions(); | |
newActions.MoveToFolder = "120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA=="; | |
rule.Actions = newActions; | |
client.CreateInboxRule(rule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.DisplayName = "test private list"; | |
MailAddressCollection members = new MailAddressCollection(); | |
members.Add("address1@host.com"); | |
members.Add("address2@host.com"); | |
members.Add("address3@host.com"); | |
client.CreateDistributionList(distributionList, members); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
const string mailboxUri = "https://exchange.domain.com/ews/Exchange.asmx"; | |
const string domain = @""; | |
const string username = @"username"; | |
const string password = @"password"; | |
NetworkCredential credential = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credential); | |
try | |
{ | |
MailMessage message = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + Guid.NewGuid().ToString(), | |
"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
client.Send(message); | |
ExchangeMessageInfoCollection messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
if (messageInfoCol.Count == 1) | |
Console.WriteLine("1 message in Inbox"); | |
else | |
Console.WriteLine("Error! No message in Inbox"); | |
MailMessage message1 = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + Guid.NewGuid().ToString(), | |
"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
client.Send(message1); | |
messageInfoCol = client.ListMessages(client.MailboxInfo.InboxUri); | |
if (messageInfoCol.Count == 2) | |
Console.WriteLine("2 messages in Inbox"); | |
else | |
Console.WriteLine("Error! No new message in Inbox"); | |
MailMessage message2 = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + Guid.NewGuid().ToString(), | |
"TestMailRefw Implement ability to create RE and FW messages from source MSG file"); | |
message2.Attachments.Add(Attachment.CreateAttachmentFromString("Test attachment 1", "Attachment Name 1")); | |
message2.Attachments.Add(Attachment.CreateAttachmentFromString("Test attachment 2", "Attachment Name 2")); | |
// Reply, Replay All and forward Message | |
client.Reply(message2, messageInfoCol[0]); | |
client.ReplyAll(message2, messageInfoCol[0]); | |
client.Forward(message2, messageInfoCol[0]); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Error in program"+ex.Message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "your.username", "your.Password"); | |
DateTime date = DateTime.Now; | |
DateTime startTime = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0); | |
DateTime endTime = startTime.AddHours(1); | |
string timeZone = "America/New_York"; | |
Appointment app = new Appointment("Room 112", startTime, endTime, "organizeraspose-email.test3@domain.com","attendee@gmail.com"); | |
app.SetTimeZone(timeZone); | |
app.Summary = "NETWORKNET-34136" + Guid.NewGuid().ToString(); | |
app.Description = "NETWORKNET-34136 Exchange 2007/EWS: Provide support for Add/Update/Delete calendar items"; | |
string uid = client.CreateAppointment(app); | |
Appointment fetchedAppointment1 = client.FetchAppointment(uid); | |
app.Location = "Room 115"; | |
app.Summary = "New summary for " + app.Summary; | |
app.Description = "New Description"; | |
client.UpdateAppointment(app); | |
Appointment[] appointments1 = client.ListAppointments(); | |
Console.WriteLine("Total Appointments: " + appointments1.Length); | |
Appointment fetchedAppointment2 = client.FetchAppointment(uid); | |
Console.WriteLine("Summary: " + fetchedAppointment2.Summary); | |
Console.WriteLine("Location: " + fetchedAppointment2.Location); | |
Console.WriteLine("Description: " + fetchedAppointment2.Description); | |
client.CancelAppointment(app); | |
Appointment[] appointments2 = client.ListAppointments(); | |
Console.WriteLine("Total Appointments: " + appointments2.Length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = GetExchangeEWSClient(); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Create the User Configuration for Inbox folder | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri); | |
UserConfiguration userConfig = new UserConfiguration(userConfigName); | |
userConfig.Dictionary.Add("key1", "value1"); | |
userConfig.Dictionary.Add("key2", "value2"); | |
userConfig.Dictionary.Add("key3", "value3"); | |
client.CreateUserConfiguration(userConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
string strContactToDelete = "John Teddy"; | |
Contact[] contacts = client.GetContacts(client.MailboxInfo.ContactsUri); | |
foreach (Contact contact in contacts) | |
{ | |
if (contact.DisplayName.Equals(strContactToDelete)) | |
client.DeleteItem(contact.Id.EWSId, DeletionOptions.DeletePermanently); | |
} | |
client.Dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Find those Conversation Items in the Inbox folder which we want to delete | |
ExchangeConversation[] conversations = client.FindConversations(client.MailboxInfo.InboxUri); | |
foreach (ExchangeConversation conversation in conversations) | |
{ | |
Console.WriteLine("Topic: " + conversation.ConversationTopic); | |
// Delete the conversation item based on some condition | |
if (conversation.ConversationTopic.Contains("test email") == true) | |
{ | |
client.DeleteConversationItems(conversation.ConversationId); | |
Console.WriteLine("Deleted the conversation item"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
MailAddressCollection members = client.FetchDistributionList(distributionLists[0]); | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
membersToDelete.Add(members[0]); | |
membersToDelete.Add(members[1]); | |
client.DeleteFromDistributionList(distributionLists[0], membersToDelete); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.Id = "list's id"; | |
distributionList.ChangeKey = "list's change key"; | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
MailAddress addressToDelete = new MailAddress("address", true); | |
//addressToDelete.Id.EWSId = "member's id"; | |
membersToDelete.Add(addressToDelete); | |
client.AddToDistributionList(distributionList, membersToDelete); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of IEWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo(); | |
// List all messages from Inbox folder | |
Console.WriteLine("Listing all messages from Inbox...."); | |
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri); | |
foreach (ExchangeMessageInfo msgInfo in msgInfoColl) | |
{ | |
// Delete message based on some criteria | |
if (msgInfo.Subject != null && msgInfo.Subject.ToLower().Contains("delete") == true) | |
{ | |
client.DeleteItem(msgInfo.UniqueUri, DeletionOptions.DeletePermanently); // EWS | |
Console.WriteLine("Message deleted...." + msgInfo.Subject); | |
} | |
else | |
{ | |
// Do something else | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
client.DeleteDistributionList(distributionLists[0],true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks info collection from exchange | |
ExchangeMessageInfoCollection tasks = client.ListMessages(client.MailboxInfo.TasksUri); | |
// Parse all the tasks info in the list | |
foreach (ExchangeMessageInfo info in tasks) | |
{ | |
// Fetch task from exchange using current task info | |
ExchangeTask task = client.FetchTask(info.UniqueUri); | |
// Check if the current task fulfills the search criteria | |
if (task.Subject.Equals("test")) | |
{ | |
//Delete task from exchange | |
client.DeleteItem(task.UniqueUri, DeletionOptions.DeletePermanently); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
Console.WriteLine("Connected to Exchange 2010"); | |
// Delete User Configuration | |
UserConfigurationName userConfigName = new UserConfigurationName("inbox.config", client.MailboxInfo.InboxUri); | |
client.DeleteUserConfiguration(userConfigName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment