How can i send a mail by smtp?

  • Thread starter Thread starter allen zhang
  • Start date Start date
A

allen zhang

I write an application with MS VStudio C#, I wanna send a mail by this
application, I use System.Web.Mail.SmtpMail class to implement this
functionality, But I found it can't accomplish authentication by SMTP
server. How can I do? Where can I find some message about it?

Thanks.

Regards.
 
MailMessage mail = new MailMessage();
mail.To = "(e-mail address removed)";
mail.From = "(e-mail address removed)";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here
SmtpMail.Send( mail );

Why do we use a url instead of something local?
(re: "http://schemas.microsoft.com/cdo/configuration/sendusername")

-Tony!-
 
Back
Top