This error is usually related with SMTP server setting. In some cases, it
is the wrong smtp server name or wrong DNS entry. Here I would suggest:
1. Double check the SMTP server is listen on port 25;
2. The SMTP grant permission to the ASP.NET application to send email. The
default security account for ASP.NET application is <ServerName>\ASPNET.
is the wrong smtp server name or wrong DNS entry. Here I would suggest:
1. Double check the SMTP server is listen on port 25;
2. The SMTP grant permission to the ASP.NET application to send email. The
default security account for ASP.NET application is <ServerName>\ASPNET.
解决方案 »
- 请教:如在ArrayList加入一个string[3],如何读取这个ArrayList里每个string的值,谢谢
- 紧急求助!!!关于dateTimePicker1使用问题!
- C#线程小问题,开了个线程,窗体却不能响应操作了,为什么??
- 串口读写程序,经过待机后失去响应,或者出现IOException :(
- 急,急,报表导入到Excel问题?
- 圆刚的采集卡问题
- 如何判断变量的类型。。。?
- 关于C#操作lotus notes发送邮件的问题
- 运行调试时,想跟进DLL的代码中,如何实现单步跟踪?
- 怎么样才能读取到coboBox控件中选择到的值呢?
- 关于Smtp Send Mail问题,高手接分!!!!!!!!!!!
- 谁有grapecity的compnentOne Grid Pro for .net的产品键或解密版?
可以具体详细一点吗?老兄,帮忙具体一点
{
MailMessage newMail=new MailMessage();
newMail.From = "[email protected]";
newMail.To = EmailAddress;
newMail.Subject = "Bug Notify !";
newMail.Body = BugDescript;
newMail.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer="smtp.163.com";
SmtpMail.Send(newMail);
}同意楼上的 163的smtp是要验证的,你可以使用SmtpMail.SmtpServer="localhost";
前题是,启动在你的iis中smtp服务器,在访问选项卡中的,中继,把本地ip添加
private void btnSend_Click(object sender, System.EventArgs e)
{
// change the cursor to hourglass
Cursor appCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
string sendString; byte [] dataToSend; string receiveData; try
{
// creating an instance of the TcpClient class
TcpClient smtpServer = new TcpClient(txtSmtpServer.Text, 25);
lstLog.Items.Add("Connection Established with " + txtSmtpServer.Text);
// creating stream classes for communication
NetworkStream writeStream = smtpServer.GetStream();
StreamReader readStream = new StreamReader(smtpServer.GetStream());
// receiving connection success
receiveData = readStream.ReadLine();
lstLog.Items.Add(receiveData); // sending From Email Address
sendString = "MAIL FROM: " + "<" + txtFrom.Text + ">\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog.Items.Add(receiveData);
// sending To Email Address
sendString = "RCPT TO: " + "<" + txtTo.Text + ">\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog.Items.Add(receiveData); // sending data
sendString = "DATA " + "\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog.Items.Add(receiveData);
// sending Message Subject and Text
sendString = "SUBJECT: " + txtSubject.Text + "\r\n" + txtMessage.Text + "\r\n" + "." + "\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog.Items.Add(receiveData); // sending Disconnect from Server
sendString = "QUIT " + "\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog.Items.Add(receiveData); // closing all open resources
writeStream.Close();
readStream.Close(); smtpServer.Close();
}
catch(SocketException se)
{
MessageBox.Show("SocketException:" + se.ToString());
}
catch(Exception excep)
{
MessageBox.Show("Exception:" + excep.ToString());
} // restoring the cursor state
Cursor.Current = appCursor; } private void btnReceive_Click(object sender, System.EventArgs e)
{ // change the cursor to hourglass
Cursor appCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
string sendString; byte [] dataToSend; string receiveData; try
{
TcpClient popServer = new TcpClient(txtPopServer.Text,110);
NetworkStream writeStream = popServer.GetStream();
StreamReader readStream = new StreamReader(popServer.GetStream()); // connect with the server
receiveData = readStream.ReadLine();
lstLog2.Items.Add(receiveData); // sending username to the server
sendString = "USER " + txtUserName.Text + "\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog2.Items.Add(receiveData); // sending password to the server
sendString = "PASS " + txtPassword.Text + "\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog2.Items.Add(receiveData); // getting the number of emails on the server
sendString = "STAT" + "\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog2.Items.Add(receiveData);
// parse the returned number into integer
Match m = Regex.Match(receiveData,@"(\s\d*\s)");
int nMails = 0; if (m.Success)
{
nMails = int.Parse(m.ToString());
} // reading emails in a loop
for (int index = 1; index <= nMails; index++)
{
string szTemp; // reading individual email
MessageBox.Show("Reading Email:" + index.ToString());
sendString = "RETR " + index.ToString() + "\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
szTemp = receiveData;
while(receiveData != ".")
{
receiveData = readStream.ReadLine();
szTemp = szTemp + "\r\n" + receiveData;
}
txtEmails.Text = txtEmails.Text +
index.ToString() + "\r\n" +
szTemp + "\r\n";
//lstMsgList.Items.Add(receiveData); }
// Disconnect from the server
sendString = "QUIT" + "\r\n";
dataToSend = Encoding.ASCII.GetBytes(sendString);
writeStream.Write(dataToSend,0,dataToSend.Length); receiveData = readStream.ReadLine();
lstLog2.Items.Add(receiveData); // freeing all open resources
writeStream.Close();
readStream.Close();
popServer.Close();
}
catch(SocketException se)
{
MessageBox.Show("SocketException:" + se.ToString());
}
catch(Exception excep)
{
MessageBox.Show("Exception:" + excep.ToString());
} // restoring the cursor state
Cursor.Current = appCursor; }
}
}
http://www.c-sharpcorner.com/asp/Code/SendMailDCHK.asp
http://www.c-sharpcorner.com/Internet/MailingAppMG.asp
http://www.codeproject.com/csharp/httpmail.asp?target=mail