我有一個發送電子郵件給我的asp.net頁面。asp.net電子郵件SmtpMail.SmtpServer.Insert(0,「」);
SmtpMail.SmtpServer.Insert(0, "");
工作正常。
這是什麼意思?當我將其更改爲SmtpMail.SmtpServer = "127.0.0.1";
時,它會失敗。
When I say SmtpMail.SmtpServer.Insert(0, "")
,我正在設置爲我的SMTP服務器?
我有一個發送電子郵件給我的asp.net頁面。asp.net電子郵件SmtpMail.SmtpServer.Insert(0,「」);
SmtpMail.SmtpServer.Insert(0, "");
工作正常。
這是什麼意思?當我將其更改爲SmtpMail.SmtpServer = "127.0.0.1";
時,它會失敗。
When I say SmtpMail.SmtpServer.Insert(0, "")
,我正在設置爲我的SMTP服務器?
其實
SmtpMail.SmtpServer.Insert(0, "");
什麼都不做。
SmtpServer
SmtpServer
屬性的類型爲String,因此您基本上調用了string.Insert(int,string),它不會影響您要調用的字符串,但會返回字符串的新實例,插。
SmtpMail.SmtpServer = "google.com";
SmtpMail.SmtpServer = SmtpMail.SmtpServer.Insert(0, "mail.");
// now SmtpMail.SmtpServer will be "mail.google.com"
就這麼你知道,SmtpServer已經過時了。您應該使用SmtpClient
代替:http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
SmtpClient client = new SmtpClient();
//...
MailMessage message = new MailMessage(from, to);
// setup mail properties...
client.Send(message);
是,如何在網頁中運行?我的意思是我的smtp服務器是什麼? SmtpMail.SmtpServer.Insert(0,「」); SmtpMail.Send(message); – Jack 2011-05-27 15:20:41
你有沒有在你的web.config中定義的smtp服務器?當你設置SmtpServer =「127.0.0.1」時,它將覆蓋web.config中的一個,但是當你不這樣做時,只需執行'SmtpMail.SmtpServer.Insert(0,「」);'什麼都不做並且離開SmtpServer使用空白字符串時,它將採用web.config中定義的字符串。 – 2011-05-27 15:22:02
這是另一個問題... \t \t \t \t \t \t \t \t mailSettings> 我正在寫入磁盤,但不知何故電子郵件來到我身邊,沒有寫入磁盤。 –
Jack
2011-05-27 15:24:40