Sending Email Messages Using Exchange Server
To send emails using Exchange Server:
- Create an instance of the ExchangeClient class.
- Specify server name, username, password and domain.
- Create an instance of the MailMessage class.
- Specify the from, to, subject and other MailMessage properties.
- Call the ExchangeClient.Send() method to send the email.
Programming Samples
The sample code below sends email messages using Exchange Server.
[C#]
// Create instance of ExchangeClient class by giving credentials ExchangeClient client = new ExchangeClient("http://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);
[VB.NET]
' Create instance of ExchangeClient class by giving credentials Dim client As ExchangeClient = New ExchangeClient("http://MachineName/exchange/username", "username", "password", "domain") ' Create instance of type MailMessage Dim msg As MailMessage = 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)
Programming Samples Using Exchange Web Services
Aspose.Email provides the ExchangeWebServiceClient class to connect to Microsoft Exchange Server using Exchange Web Services. The code snippets that follow uses EWS to send emails using Microsoft Exchange Server.
[C#]
// Create instance of ExchangeWebServiceClient class by giving credentials ExchangeWebServiceClient client = new ExchangeWebServiceClient("https://exchange-server-host/ews/Exchange.asmx", "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);
[VB.NET]
' Create instance of ExchangeWebServiceClient class by giving credentials Dim client As ExchangeWebServiceClient = New ExchangeWebServiceClient("https://exchange-server-host/ews/Exchange.asmx", "username", "password", "domain") ' Create instance of type MailMessage Dim msg As MailMessage = 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)
0 comments:
Post a Comment