How do I Authenticate to a SMTP Server using c#

  • Thread starter Thread starter Curtis Ransom
  • Start date Start date
C

Curtis Ransom

I am trying to send an email through a smtp server on a different box.
In CDO there was a group of Configurations (referencing the cdo
schemas) I could set to do the authentication. Well in .NET, all I
see are the MailMessage and SmtpMail objects. I noticed a
MailMessage.Fields property (maybe similar to Configuration.Fields
with CDO), but there is no documentation on MSDN. I'd appreciate any
guidance on this. Thanks.

Curtis
 
Based on what you say it sounds like you want to send an email from your
csharp program.

If I'm correct in what I assume here is the way you would do it.

you need the System.Web.Mail namespace which means you'll need to add a
reference to the System.Web.dll.

Then the following is how you'd go about you business

MailMessage Message = new MailMessage();
Message.To = "toaddress";
Message.From = "from address";
Message.Subject = "subject";
Message.Body = "body";

SmtpMail.SmtpServer = "Your mail server goes here";

SmtpMail.Send(Message);


That should get you going. SmtpMail is a static class so you just set the
SmtpServer value and then call the Static Send method off it passing in the
MailMessage Object. There is also an overload on Send() that will allow you
to add all the address, subject, body stuff without constructing a
MailMessage Object if you don't want to.

Thanks.

Casey
 
Sorry about this you said Authenticate... My bad. I'll see if I can track
this down.

Casey
 
Sorry about my original reply.

It doesn't appear that the built in SmtpMail class will do what you need.
It appears that it relys on a smarthost server that will blindly relay for
you without authentication. I'm not sure if this is a solution for you but
you could install the smtp service on your local machine and then setup the
outbound security on it to authenticate to the smtp server you'd like to
relay through. This isn't a very elegant solution, but it's better then
writing your own SMTP protocol class.

-Casey
 
Back
Top