-1
在Windows窗體我寫了一個發送郵件的代碼,我把郵件設置放在app.config中,你能檢查我的代碼嗎?它是否正確?在Windows窗體中發送郵件?
<configuration>
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="mail.mydomain.com" password="xxxxxx" port="25" userName="[email protected]"/>
</smtp>
</mailSettings>
MailMessage msg = new MailMessage();
msg.Subject = txtSubject.Text;
msg.To.Add(txtTO.Text);
msg.From = new MailAddress("[email protected]");
msg.Body = txtDescription.Text;
System.Net.Configuration.MailSettingsSectionGroup mMailSettings=null ;
string mMailHost = mMailSettings.Smtp.Network.Host;
SmtpClient mailClient = new SmtpClient(mMailHost);
mailClient.Send(msg);
這與Windows窗體有什麼關係? – MrLane 2012-03-23 06:57:04
您將'mMailSettings'設置爲'null',但是您正在調用其子元素? – Raptor 2012-03-23 06:57:29
我收到錯誤,System.Net.Configuration.MailSettingsSectionGroup mMailSettings; string mMailHost = mMailSettings.Smtp.Network.Host; – 2012-03-23 07:11:15