We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Send emails from an application

I would like to send emails from an application running on an application server through Microsoft Exchange which is on another network.


Please share the detail how can I do this.


This message was posted using Email2Forum by Tahir Manzoor.

Hi Jason,


Thank you for using Aspose.Email.

Depending upon the version of Exchange Server you are using, you can use Aspose.Email’s ExchangeClient or ExchangeWebService Cleint for sending emails through your exchange client. You can further refer to Programming Exchange section of our documentation for details.

Working With WebDav Protocol

For Exchange Server 2003 and 2007 WebDav Protocol, you can use the following sample code for sending email:

<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:gray”>// Create instance of
ExchangeClient class by giving credentials<o:p></o:p>

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 = "

sending message from exchange server

";

// Send the message

client.Send(msg);


Working with Exchange Web Service (EWS)

For Exchange Server 2007 and above with EWS, you can use our IEWSCleint for sending email as shown in the following sample code:

// 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 = "

sending message from exchange server

"
;
 // Send the message
client.Send(msg);

Please feel free to write to us if you have any further query/inquiry in this regard. We'll be glad to assist you further.

Hi Kashif

Thanks for the info… I am testing with Exchange 2010 but want a solution for all from 2007.

Using your code snippet I get a variety of different responses depending on the uri used:

IEWSClient client = EWSClient.GetEWSClient(“https:[//outlook.office365.com/ews/exchange.asmx](https://outlook.office365.com/ews/exchange.asmx)”, “testUser”, “pwd”, “domain”);

Internal address: https://cpt.companyname.com/owa/

Response = The request failed with HTTP status 440: Login Timeout.

External address: https://exchange.companyname.com/owa :

Response = The request failed with an empty response.

I am sure the username, password and domain fields are correct.

Do you have any suggestions on how I can get this to work with Aspose Emails?

Thanks

Jason

Hi Jason,


You can use the ExchangeWebService (EWS) cleint with Exchange Server 2007 as well. The Exchange Server URI for EWS is always of the form: https://domain.com/ews/exchange.asmx.

You can find this URI by Ctrl+Left Click on the Microsoft Outlook client icon in notifications area of your PC and selecting the Test Auto-Email Configuraiton option. After providing the user name and password and pressing the Test button, it will take some time to retrieve the results which will contain this URI as well, ending in “.asmx”. For further information, please refer to this helping article. Please let us know if we can be of any additional help to you in this regard.

Hi Kashif


You Sir, are a legend.

The POC to integrate into our application is working . Thank you for your help…

Jason

Hi Jason,


Thank you for sharing the feedback and please feel free to write to us in case you have any inquiry related to Aspose.Email. We’ll try to assist you further as soon as possible.