我在我的網站上有聯繫頁面,我希望用戶輸入他們的姓名和電子郵件ID(無密碼)並按下按鈕發送電子郵件。通過SMTP發送電子郵件
我做了谷歌和所有的解決方案我收到需要用戶密碼,
public static void SendMessage(string subject, string messageBody, string toAddress, string ccAddress, string fromAddress)
{
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient();
// Set the sender's address
message.From = new MailAddress(fromAddress);
// Allow multiple "To" addresses to be separated by a semi-colon
if (toAddress.Trim().Length > 0)
{
foreach (string addr in toAddress.Split(';'))
{
message.To.Add(new MailAddress(addr));
}
}
// Allow multiple "Cc" addresses to be separated by a semi-colon
if (ccAddress.Trim().Length > 0)
{
foreach (string addr in ccAddress.Split(';'))
{
message.CC.Add(new MailAddress(addr));
}
}
// Set the subject and message body text
message.Subject = subject;
message.Body = messageBody;
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtpHost";
smtp.Port =portno;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential("fromEmail", "fromPassword");
smtp.Timeout = 20000;
}
// Send the e-mail message
smtp.Send(message);
}
但我不希望強迫用戶輸入密碼。有沒有其他解決方案使用SMTP?
我得到的錯誤是A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
您似乎意外地寫了一個網絡釣魚程序。你不應該詢問用戶密碼。很可能您需要獲取SMTP服務器的密碼,因爲匿名發送通常是鎖定的。這將是您控制的密碼,而不是您的用戶。 – 2013-05-13 17:56:46
是的......這是合乎邏輯的......我也嘗試過,但我收到錯誤信息爲「發送電子郵件失敗」。我確定用戶名和密碼正確 – user1181942 2013-05-13 18:07:35
InnerException屬性將幫助您解決此問題。 – 2013-05-13 18:11:03