Tuesday 6 November 2012

How to send email using microsoft exchange in vb.net



Sending Email Messages Using Exchange Server

To send emails using Exchange Server:
  1. Create an instance of the ExchangeClient class.
  2. Specify server name, username, password and domain.
  3. Create an instance of the MailMessage class.
  4. Specify the from, to, subject and other MailMessage properties.
  5. 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


                                                            
 
Design by Abhinav Ranjan Sinha