I click btnOK button, the email can send OK, but click btnFail button, the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid! Many thanks!
"Syntax error, command unrecognized. The server response was: authentication failed,decode user password error"
I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!
//------------------------------------------.ASPX Code------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnOK" runat="server" OnClick="btnOK_Click" Text="Send Email OK" />
<asp:Button ID="btnFail" runat="server" OnClick="btnFail_Click" Text="Send Email Fail" /></div>
</form>
</body>
</html>//------------------------------------------.ASPX Code------------------------------------------------
//------------------------------------------.CS Code------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Web.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}private const string mySMTP = "smtp.21cn.com";
private const string userName = "qazwsx456"; //The valid username is qazwsx456
private const string password = "a12345"; // The valid password is a12345private const string from = "qazwsx456@21cn.com";
private const string to = "salehouse@21cn.com";protected void btnOK_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage();
message.From = from;
message.To = to;
message.Subject = "Subject";
message.Body ="Body";message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);SmtpMail.SmtpServer = mySMTP;
SmtpMail.Send(message);}
protected void btnFail_Click(object sender, EventArgs e)
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(
new System.Net.Mail.MailAddress(from),
new System.Net.Mail.MailAddress(to)
);
message.Subject = "Subject";
message.Body = "Body";System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = mySMTP;
client.Port = 25;client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(userName, password);
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.Send(message);}
}
//------------------------------------------.CS Code------------------------------------------------
SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files
SuperCool Random Number Generator
![]() |
0 |
![]() |
I think you need to set the credentials differently
check this out
http://systemnetmail.com/faq/4.2.aspx
probably the best reference for mail in asp.net
Hope That Helps
All that wander, are not lost...
What were we talkin bout
![]() |
0 |
![]() |
I have read http://systemnetmail.com/faq/4.2.aspx , I think the code in btnOK_Click and the code in btnFail_Click is the most similar, but I'm still strange why click btnOK button, the email can send OK, but click btnFail button,occur error!
SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files
SuperCool Random Number Generator
![]() |
0 |
![]() |
system.web.mail = framework 1.1
system.net.mail = framework 2.0
I don't think you can run both on the same page - each website has 1 framework associated with it in IIS
thats the only thing I see different - the code looks OK
Hope That Helps
All that wander, are not lost...
What were we talkin bout
![]() |
0 |
![]() |
I'm sure that you can run the both on the same page, I have tested it!
If the two code looks OK, why is one Ok and another failed?
SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files
SuperCool Random Number Generator
![]() |
0 |
![]() |
Have spent one whole day digging out this problem.
Basically, it due to 21cn.com 's smtp doesn't completely follows RFC.
According to RFC 2554 ( http://tools.ietf.org/html/rfc2554#ref-initial-response ), when client authenticating itself to a smtp server, it should use "an optional base64-encoded response", and "The optional initial-response argument to the AUTH command is used to save a round trip".
The .net 2.0 smtpclient class did make use of this "optional response", and 21cn.com's smtp just don't support it. I have direct contact with 21cn's smtp administrator, and the reply is:
"We currently don't have plan to support this optional response."
![]() |
0 |
![]() |
Thanks so much!
Is the Optional Response necessary? is there some benefit to use Optional Response ? why does the smtp of 21cn work normally?
SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files
SuperCool Random Number Generator
![]() |
0 |
![]() |