PDA

View Full Version : cho hỏi ASP.NET



vdhieu
14-07-2005, 21:51
mình có làm thử một đoạn code gởi mail sao nó chạy lại báo lỗi sau:

The transport failed to connect to the server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The transport failed to connect to the server.

Source Error:


Line 269: msg.BodyFormat = MailFormat.Html;
Line 270: SmtpMail.SmtpServer = "MyMailServer";
Line 271: SmtpMail.Send(msg);
Line 272: }

code của mình như sau:
MailMessage msg = new MailMessage();
StringWriter strWriter = new StringWriter();
HtmlTextWriter htmltxWriter = new HtmlTextWriter(strWriter);
htmltxWriter.RenderBeginTag("head");
htmltxWriter.RenderBeginTag("title");
htmltxWriter.Write("Thank you");
htmltxWriter.RenderBeginTag("body");
htmltxWriter.WriteLine("Mail Test");
htmltxWriter.WriteLine("Test mail");

htmltxWriter.RenderEndTag();
msg.From = "conrua@yahoo.com";
msg.To = emailBan.Trim();
msg.Subject = "Thank you";
msg.Body = strWriter.ToString();
msg.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = "MyMailServer";
SmtpMail.Send(msg);

Các bạn có cách nào sửa không?

thitkhohotvit
14-07-2005, 22:17
Bạn thử chuyển SmtpMail.SmtpServer = "MyMailServer"; thành SmtpMail.SmtpServer = "localhost"; xem sao,thông thường mailserver sẽ là localhost

vdhieu
14-07-2005, 23:44
MSDN hướng dẫn là nếu bỏ khai báo SmtpMail.SmtpServer thì nó sẽ tự động lấy mail server của windows để gửi mail và mình làm thử bỏ dòng khai báo đó nó cũng báo lỗi:

Exception Details: System.Runtime.InteropServices.COMException: The "SendUsing" configuration value is invalid.

Mình cũng làm theo kiểu của bạn rồi cũngn báo lỗi như của mình thôi bạn ơi. có ai giúp mình với.

White Rose
15-07-2005, 01:37
MSDN hướng dẫn là nếu bỏ khai báo SmtpMail.SmtpServer thì nó sẽ tự động lấy mail server của windows để gửi mail và mình làm thử bỏ dòng khai báo đó nó cũng báo lỗi:

Exception Details: System.Runtime.InteropServices.COMException: The "SendUsing" configuration value is invalid.

Mình cũng làm theo kiểu của bạn rồi cũngn báo lỗi như của mình thôi bạn ơi. có ai giúp mình với.

Ensure that your computer is installed a mail server

vdhieu
15-07-2005, 14:18
mình đã IIS thì tức nhiên phải có mail server rồi mà mình cũng đã kiểm tra rồi có mail server mà. vào window service thì mail server đã chạy tự động luôn rồi bạn ơi

nguoikicuc
16-07-2005, 02:57
Nếu đã chắc chắn có install SMTP server rồi thì kiểm tra xem server có works dàng hoàng không, rồi hãy tính tới chuyện dùng program để send mail.

Thứ nhất, nếu computer is running behind a firewall, thì phải setup virtual server để firewall cho smtp server sử dụng port 25.

Sau đó test SMTP server bằng cách dùng MS Outlook Express, hay MS Outlook, set SMTP server tới local machine, rồi thử send mail tới external mail server xem mail có đi được không, và có nhận được mails từ ngoài vào không. Có thể dùng hotmail hay yahoo mail để test.

Nếu không gửi và nhận được mails dùng MS Outlook/Outlook Express thì setup sai rồi, cần phải chỉnh lại trước khi có thể dùng program mà send mails.

Chúc may mắn.

Tetsu81vn
28-07-2005, 00:30
bạn tham khảo trang SystemWebMail FaQ này, có thể giúp ích cho bạn http://systemwebmail.net/faq/2.3.aspx