11

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("Me@myCompany.com",
                "Them@mycompany.com",
                "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.

Scott Langham
  • 58,735
  • 39
  • 131
  • 204
  • Do you have forwarding enabled on the account that you are sending the email as? I think it's something the Exchange admin needs to set on that account to allow you to send email with that account without using authentication. – Jim W Aug 28 '09 at 15:23

4 Answers4

7

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.

jasonmw
  • 1,138
  • 9
  • 20
4

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

EBarr
  • 11,826
  • 7
  • 63
  • 85
Terry
  • 51
  • 2
3

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

Austin Salonen
  • 49,173
  • 15
  • 109
  • 139
0

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("youremailaddress@yourdomain.com");  

EmailMessage message = new EmailMessage(service);  
message.Subject = "my subject";  
message.Body = "my body";  
message.ToRecipients.Add("my_target@example.com");  
message.Save();  

message.SendAndSaveCopy();
mkinawy
  • 375
  • 1
  • 10