2013-02-26 33 views
0

如何製作允許用戶從任何域(Gmail,Hotmail,雅虎等)向管理員發送電子郵件的「聯繫我們」表單。我的意思是,任何有電子郵件地址的用戶都可以發送電子郵件給管理員的電子郵件地址。目前用戶只能在發送郵件時才能發送Gmail帳戶。請幫助並提供任何解決方案和建議。 謝謝。製作發送來自任何域名的電子郵件的聯繫表格

回答

0

在Asp.net中,您可以設置任何域的​​用戶電子郵件,但它應該是有效的。在Mail類的From Property中設置用戶電子郵件。

protected void SendMail() 
{ 
    // Gmail Address from where you send the mail 
    var fromAddress = "[email protected]"; 
    // any address where the email will be sending 
    var toAddress = YourEmail.Text.ToString(); 
    //Password of your gmail address 
    const string fromPassword = "Password"; 
    // Passing the values and make a email formate to display 
    string subject = YourSubject.Text.ToString(); 
    string body = "From: " + YourName.Text + "\n"; 
    body += "Email: " + YourEmail.Text + "\n"; 
    body += "Subject: " + YourSubject.Text + "\n"; 
    body += "Question: \n" + Comments.Text + "\n"; 
    // smtp settings 
    var smtp = new System.Net.Mail.SmtpClient(); 
    { 
     smtp.Host = "smtp.gmail.com"; 
     smtp.Port = 587; 
     smtp.EnableSsl = true; 
     smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 
     smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); 
     smtp.Timeout = 20000; 
    } 
    // Passing values to smtp object 
    smtp.Send(fromAddress, toAddress, subject, body); 
} 

fromAddress可以是任何有效的電子郵件地址。

+0

好像我只能使用它的gmail ids的「fromAddress」。如果用戶可以從任何地址發送郵件,可能是gmail,yahoo,hotmail等? – 2013-02-26 06:59:10

+0

用戶可以使用「fromAddress」從任何地址發送郵件,可能是gmail,yahoo,hotmail。 – Saurabh 2013-02-26 07:02:25

+0

當我使用gmail帳戶作爲「fromaddress」時它的工作原理。但是當我嘗試使用任何其他帳戶是yahoo或hotmail時,它會給出錯誤「SMTP服務器需要安全連接或客戶端未經過身份驗證。服務器響應是:5.5.1需要身份驗證。「 – 2013-02-26 07:30:32

相關問題