Solve .NET platform mail Send CDO.Message error

xiaoxiao2021-03-06  43

I like to C #, no reason to leave it to learn another language, and the ASP can easily call CDO and attach an account and password to send an email, but the system.web.mail namespace has not yet let me wait Enter the properties of the username and password, in the art of other colleagues, try it out, here to share with you.

Due to how much the program is written on the .NET platform, it is never used to express it. It seems that it seems to be thought, so I like C # and only use c # to write these code, VB.NET and J #, Friends can change it slightly ...

Private Static Int Gotosendmail (String Body, String To)

{

Try

{

System.Web.mail.mailmessage mm = new system.Web.mail.mailMessage ();

mm.bodyformat = system.Web.mail.mailFormat.html;

mm.from = "

Xxx@xxx.com ";

mm.to = TO;

mm.bodyencoding = system.text.Encoding.getencoding (936);

mm.subject = "Hello! I am a dream cat. Net studio hopes to work with you."

mm.body = body;

mm.fields ["

Http://schemas.microsoft.com/cdo/configuration/sendusing "] = 2;

mm.fields ["

http://schemas.microsoft.com/cdpo/configuration/sendemailaddress "] ="

Xxx@xxx.com "; // Send the address; if mm.from wrote this, you can do not write this sentence

mm.fields ["

http://schemas.microsoft.com/cdpo/configuration/smtpaccountname "] ="

Xxx@xxx.com ";

mm.fields ["

http://schemas.microsoft.com/cdo/configuration/sendusername "] =" xxx "; // Verification account: sender mailbox account

mm.fields ["

http://schemas.microsoft.com/cdo/configuration/sendpassword "] =" xxx "; // Verification Password: sender mailbox password

mm.fields ["

http://schemas.microsoft.com/cdo/configuration/smtpauthenticate "] = 1; // Verification level 0, 1, 2

mm.fields ["

http://schemas.microsoft.com/cdo/configuration/languagecode "] = 0x0804; // language code

mm.fields ["

http://schemas.microsoft.com/cdpo/configuration/smtpserver "] ="

SMTP.XXX.com "; // SMTP Server

System.Web.mail.smtpmail.smtpserver = "

SMTP.XXX.com

"; // The above sentence is heavy, this sentence can replace the second sentence system.web.mail.smtpmail.send (mm);

Return 0;

}

Catch (System.exception E)

{

Response.write (E.MESSAGE E.STACKTRACE E.SOURCE);

Return -1;

}

}

This program is passed on the XP and 2000 Server IIS6

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

New Post(0)