Sample Code on Sending Email using ASP.NET 1

Our mail server is configured with SMTP authentication and all your code need to use SMTP Authentication before you can send email. If your code does not use SMTP authentication, the email will not get sent.

                                                        
1 private void Page_Load(object sender, System.EventArgs e)
2 {
3 MailMessage mail = new MailMessage();
4 mail.To = "me@mycompany.com";
5 mail.From = "you@yourcompany.com";
6 mail.Subject = "this is a test email.";
7 mail.Body = "Some text goes here";
8 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
9 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
10 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here
11
12 SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here
13 SmtpMail.Send( mail );
14 }
15


Note:
Replace mail.mycompany.com with mail.yourdomain.com
Replace my_username with your email username e.g test@test.com
Replace password with your email password

  • 0 Usuários acharam útil
Esta resposta lhe foi útil?

Artigos Relacionados

Sample Code on how to send email using ASP.NET 2

For ASP.NET 2 you no longer using System.Web.Mail, but you will be using System.Net.Mail and the...

Query MySQL Database in ASP.net

1 2 3 <%@ Page Language="VB"...