How do I authenticate to send an email
How do I authenticate to send an email? Printer Friendly Email This FAQ
If you are using the .NET Framework 1.0, this cannot be done. However, in the 1.1 version, the MailMessage.Fields property was added. This allowed access to the underlying CDO.Message fields.
The following example demonstrates sending your username and password to the SMTP server to provide authentication.
[ C# ]
[ VB.NET ]
The following example demonstrates sending your username and password to the SMTP server to provide authentication.
[ C# ]
private void Page_Load(object sender, System.EventArgs e) { MailMessage mail = new MailMessage(); mail.To = "me@mycompany.com"; mail.From = "you@yourcompany.com"; 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 ); }
[ VB.NET ]
Private Sub Page_Load(sender As Object, e As System.EventArgs) Dim mail As New MailMessage() mail.To = "me@mycompany.com" mail.From = "you@yourcompany.com" 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 SmtpMail.Send(mail) End Sub 'Page_Load
http://www.systemwebmail.com/faq/3.8.aspx
http://blog.joycode.com/
http://blog.joycode.com/joy/posts/11405.aspx
http://www.cnblogs.com/
posted on 2004-01-28 20:26 sunhai的net世界 阅读(999) 评论(1) 编辑 收藏 举报