Scott Langham
Scott Langham

Reputation: 60311

How to send email via exchange server without using smtp?

I'm trying to send an email from c# code via our company's exchange server.

System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("exchangebox1.mycompany.com");
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage("[email protected]",
                "[email protected]",
                "title here",
                "body here");
            client.Send(msg);

When I run this I get SmptException saying "Service not available, closing transmission channel. The server response was 4.3.2 Service not available, closing transmission channel".

I'm interpreting this to mean SMTP is not enabled on our exchange box and that I need to use native Exchange Server commands to send the mail. Is this right, or should SMTP always work?

Additionally, is it possible the exchange server could have been configured to only allow certain computers/users to send main via SMTP?

How can I send mail via the Exchange Server without using SMTP?

Thanks.

Upvotes: 11

Views: 37464

Answers (4)

mkinawy
mkinawy

Reputation: 375

I know this is an old thread, but for completeness, you should consider the Microsoft Exchange WebServices nuget package:

https://www.nuget.org/packages/Microsoft.Exchange.WebServices

ExchangeService service = new ExchangeService();  
service.AutodiscoverUrl("[email protected]");  

EmailMessage message = new EmailMessage(service);  
message.Subject = "my subject";  
message.Body = "my body";  
message.ToRecipients.Add("[email protected]");  
message.Save();  

message.SendAndSaveCopy();

Upvotes: 0

Terry
Terry

Reputation: 51

You can use the new Exchange Web Services Managed API 1.0. it seems to be the best solution. heres the link.

http://msdn.microsoft.com/en-us/library/dd637749(v=exchg.80).aspx
https://blogs.technet.com/b/exchange/archive/2009/04/21/3407328.aspx
The accept will accept distribution lists as well.

The 2.0 version of the API
http://msdn.microsoft.com/en-us/library/office/dd633709.aspx

Upvotes: 4

Austin Salonen
Austin Salonen

Reputation: 50225

Try adding these two lines prior to sending:

client.UseDefaultCredentials = true;
client.EnableSsl = true;

It's most likely an issue with there being no credentials so I'll cheat a little from Google...
From dailycode.net

Upvotes: 3

jasonmw
jasonmw

Reputation: 1138

You can use the WCF Exchange Server Mail Transport an example of how to implement is Here

Specifically regarding sending messages it says

When an application sends a message, it calls the Send method on the current output channel, which must be open. The output channel serializes the message to a string and creates the message in the Drafts folder. It sets the appropriate values in the e-mail fields. When the message has been created, it is moved into the Outbox. This occurs through CEMAPI on the device or through Exchange Web Services on the desktop. On the device, messages in the Outbox are synchronized with other outgoing messages, as defined by ActiveSync.

Upvotes: 7

Related Questions