Send an email using System.Web.mail

zhaozj2021-02-16  47

Send an email using System.Web.mail

Use System.Web.mail to send emails by the mail server you want to verify, the following is a class that Scott Water writes in dottext, which is more convenient to use, the code of the entire class is as follows:

Using system;

Using system.web.mail;

Namespace ZZ

{

///

/// systemmail's summary description.

///

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 Email 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/cdpo/configuration/smtpauthenticate", "1"); // Basic Authentication

Em.fields.add ("http://schemas.microsoft.com/cdpo/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 You can view http://systemwebmail.com

转载请注明原文地址:https://www.9cbs.com/read-16957.html

New Post(0)