Use System.Web.Mail to send mail through a mail server that needs to be validated

Source: Internet
Author: User
Tags mail mailmessage
web| Send mail | server | mail server uses System.Web.Mail to send mail through a mail server that needs to be authenticated



Using System.Web.Mail to send mail through a mail server that needs to be validated, the following is a mail-sending class written by Scott Water in Dottext, which is easy to use, with the entire class code as follows:

Using System;

Using System.Web.Mail;



Namespace ZZ

{

///

Summary description of the systemmail.

///

public class Systemmail

{

private string _adminemail;

private string _smtpserver = "localhost";

private string _password;

private string _username;



Public Systemmail ()

{

}





public string AdminEmail

{

Get{return _adminemail;}

Set{_adminemail = value;}

}





public string SmtpServer

{

Get{return _smtpserver;}

Set{_smtpserver = value;}

}





public string Password

{

Get{return _password;}

Set{_password = value;}

}





public string UserName

{

Get{return _username;}

Set{_username = value;}

}



public bool Send (string to, string from, string subject, String message)

{

Try

{

MailMessage em = new MailMessage ();

Em. to = to;

Em. from = from;

Em. Subject = Subject;

Em. BODY = message;



Found out how to send authenticated emailed via System.Web.Mail at http://SystemWebMail.com (Fact 3.8)

if (this. UserName!= null && this. Password!= null)

{

Em. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); Basic Authentication

Em. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendusername", this. UserName); Set your username here

Em. Fields.Add ("Http://schemas.microsoft.com/cdo/configuration/sendpassword", this. Password); Set your password here

}



Smtpmail.smtpserver = this. SmtpServer;

Smtpmail.send (EM);

return true;

}

Catch

{

return false;

}

}



}

}

Need more information to view http://SystemWebMail.com



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.