I wrote a mail sending class:
Public class sendmail
{
Private Static string m_username;
Private Static string m_password;
Private Static string m_hostname;
Static string returnmsg = "";
Public static void newmailserver (string user, string PWD, string host ){
M_username = user;
M_password = PWD;
M_hostname = host;
}
Public static string send (string from, string sentto, string CC, string
BC, string subject, string body)
{
Try
{
Mailmessage message = new mailmessage (New mailaddress (from, "Rui" +
(Char) 0xd8 + "Chen", system. Text. encoding. utf8), new mailaddress (sentto ));
Message. Subject = subject;
Message. Body = body;
Message. isbodyhtml = true;
Smtpclient mailclient = new smtpclient ();
Mailclient. Host = m_hostname;
Mailclient. Credentials = new networkcredential (m_username, m_password );
Mailclient. usedefacrecredentials = false;
Mailclient. Timeout = 100000;
Mailclient. deliverymethod = smtpdeliverymethod. Network;
Mailclient. Send (Message );
Return returnmsg;
}
Catch (system. net. Mail. smtpexception sex)
{
Return sex. statuscode. tostring () + ":" + sex. Source + sex. tostring ();
}
}
Private Sendmail ()
{
}
}
However, an error occurs during the call:
Mailboxnamenotallowed: System system. net. Mail. smtpexception: mailbox name
Not allowed. The server response was: You are not authorized to send mail
>, Authentication is required
System. net. Mail. mailcommand. checkresponse (smtpstatuscode statuscode, string
Response) at system. net. Mail. mailcommand. Send (smtpconnection Conn, byte []
Command, string from) at system. net. Mail. smtptransport. Sendmail (mailaddress
From, mailaddresscollection recipients, smtpfailedrecipientexception &
Exception) at system. net. Mail. smtpclient. Send (mailmessage message)
Merlion. Web. Mail. Sendmail. Send (string from, string sentto, string CC, string
BC, string subject, string body) in C:/Documents ents and settings/Chen Rui/My
Documents/Visual Studio 2005/websites/website3/app_code/sendmail. CS: Line 53
8. Why? After an afternoon, I was depressed. You can't simply use socket to write your own SMTP implementation.