2010-02-16 39 views
4

我想創建一個聯繫我們頁面,該網站的訪問者可以留言給網站管理員。接收電子郵件主機域名電子郵件ID來自任何用戶訪問網站

說我m跑這個網站 www.example.com 和我有一個id [email protected] 現在新的訪問者訪問我的網站,填補了我們聯絡表單。 他填補

FROM - [email protected] 主語查詢 MESSAGE-我的問題....

我要發送此消息作爲郵件[email protected]

成功發送郵件時,我想發送此用戶自動生成的郵件作爲確認。

我需要爲此做些什麼,我的託管服務器是GoDaddy的

我想下面的代碼。

try 
    { 
     MailMessage mailMessage = new MailMessage(); 
     mailMessage.From = new MailAddress(txtEmailId.Text); 
     mailMessage.To.Add(new MailAddress("[email protected]")); 
     mailMessage.Subject = txtSubject.Text; 
     mailMessage.Body = txtMessage.Text; 
     mailMessage.IsBodyHtml = false; 
     mailMessage.Priority = MailPriority.High; 
     SmtpClient sc = new SmtpClient("relay-hosting.secureserver.net"); 
     //sc.Credentials = new System.Net.NetworkCredential("[email protected]", "MyPassword"); 
     sc.Send(mailMessage); 
    } 
    catch (Exception ex) 
    { 
     Label1.Text = "An Error has occured : "+ex.Message; 
    } 

嘗試發送郵件時發生此錯誤。

郵箱名稱不允許。服務器 的迴應是:對不起,您的郵件是 在行政上被拒絕。 (#5.7.1)

回答

1

它看起來像從您的代碼中指定郵件消息的From字段基於用戶填寫的電子郵件地址。郵件服務器郵件拒絕接收此郵件,並且僅允許來自域的電子郵件名稱example.com或者服務器名稱本身。我在您的From字段必須是原始站點域之前碰到的這個...

如果你想爲形式的郵件收件人直接回復的能力,使用ReplyTo領域,而不是來自:

MailMessage mailMessage = new MailMessage(); 

//try using a domain address that matches your server and/or site. 
//the email address itself may also have to exist depending on the mail server. 
mailMessage.From = new MailAddress("[email protected]"); 

//set the replyto field 
mailMessage.ReplyTo = new MailAddress(txtEmailId.Text); 

//send the mail... 

希望這可以幫助...

編輯:

編輯完你的問題後,上面仍然是相關的。很可能您不能在您自己的網站域example.com以外使用From地址。如果你想發送兩個請求副本(一個聯繫@ example。COM和其他用戶作爲確認),你只需要添加到To屬性:

MailMessage mailMessage = new MailMessage(); 

//try using a domain address that matches your server and/or site. 
//the email address itself may also have to exist depending on the mail server. 
mailMessage.From = new MailAddress("[email protected]"); 

//add the contact email address to the To list 
mailMessage.To.Add(new MailAddress("[email protected]")); 

//add the user email address to the To list 
mailMessage.To.Add(new MailAddress(txtEmailId.Text)); 

//set the replyto field 
mailMessage.ReplyTo = new MailAddress(txtEmailId.Text); 

//send the mail... 

如果您需要添加一個簡單的信息爲用戶確認電子郵件,您也可以這樣做:

try 
{ 
    MailMessage mailMessage = new MailMessage(); 
    mailMessage.From = new MailAddress("[email protected]"); 
    mailMessage.To.Add(new MailAddress("[email protected]")); 
    mailMessage.ReplyTo = new MailAddress(txtEmailId.Text); 
    mailMessage.Subject = txtSubject.Text; 
    mailMessage.Body = txtMessage.Text; 
    mailMessage.IsBodyHtml = false; 
    mailMessage.Priority = MailPriority.High; 
    SmtpClient sc = new SmtpClient("relay-hosting.secureserver.net"); 
    //sc.Credentials = new System.Net.NetworkCredential("[email protected]", "MyPassword"); 

    //send to only the [email protected] first 
    sc.Send(mailMessage); 

    mailMessage.To.Clear(); 
    mailMessage.To.Add(new MailAddress(txtEmailId.Text)); 

    //add a simple message to the user at the beginning of the body 
    mailMessage.Body = "Thank you for submitting your question. The following has been submitted to [email protected]: <br/><br/>" + mailMessage.Body; 

    //send the acknowledgment message to the user 
    sc.Send(mailMessage); 

} 
catch (Exception ex) 
{ 
    Label1.Text = "An Error has occured : "+ex.Message; 
} 
+0

@KP你是對的,但THR在xplaining Q一些錯誤,PLZ檢查編輯 –

0

這可能是Serverfault.com問題,任何如何

,你需要檢查這些選項

聯繫首頁 - >配置 - >電子郵件 選項 - > - 電子-Mail Transport Method = sendemail

參考553 sorry, your mail was administratively denied。 (#5.7.1)

+0

@Asad THR在xplaining Q一些錯誤,PLZ檢查編輯 –

+0

可以PLZ標記「編輯」在你的版本,我不能讓你的版本 –

相關問題