2014-06-26 27 views
-6

我是編程新手。我想發送一封電子郵件給用戶,他們無法查看我的原始地址,這在收到的郵件中是可見的。如何使用c#從接收器中隱藏電子郵件地址?

這是我的代碼。請指導我必須做些什麼才能做到這一點。

try 
{ 
    MailMessage Msg = new MailMessage(); 
    // Sender e-mail address. 
    Msg.From = new MailAddress(txtUsername.Text, "Rajesh", System.Text.Encoding.UTF8); 
    // Recipient e-mail address. 
    Msg.To.Add(txtTo.Text); 
    Msg.ReplyTo =new MailAddress("[email protected]"); 
    //Msg.ReplyTo = ("[email protected]"); 
    Msg.Subject = txtSubject.Text; 
    Msg.Body = txtBody.Text; 
    Msg.SubjectEncoding = System.Text.Encoding.UTF8; 
    //txtUsername.Text, 
    // your remote SMTP server IP. 
    SmtpClient smtp = new SmtpClient(); 
    smtp.Host = "smtp.gmail.com"; 
    smtp.Port = 587; 
    smtp.Credentials=new System.Net.NetworkCredential(txtUsername.Text,txtpwd.Text); 
    smtp.EnableSsl = true; 
    smtp.Send(Msg); 
    Msg = null; 
    ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Mail sent successfully!.Thank god.');if(alert){ window.location='default.aspx';}", true); 

    //ScriptManager.RegisterStartupScript(); 
    //ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true); 
    //Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');window.close();</script>"); 

    //if(alert){ window.location='SendMail.aspx';} 
    //} 

    //Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='default.aspx';}</script>"); 
} 
catch (Exception ex) 
{ 
    Console.WriteLine("{0} Exception caught.", ex); 
} 
} 

請指導我實現目標的正確方法。

+0

打開一個單獨的帳戶僅用於發送這些消息? – David

+0

所以你跑這個?會發生什麼? –

+0

它正確發送消息,接收方收到來自「[email protected]」的消息,顯示名稱爲「Rajesh」,並按照編碼發送給「[email protected]」。但我的要求是將「[email protected]」隱藏到接收方或替換電子郵件地址。 –

回答

7

那麼,這裏是一些東西:你不能。點。必須是有效的電子郵件地址。

谷歌真的不喜歡玩垃圾郵件的人 - 這是你在技術上做的。 Google不會用任意電子郵件發送您的電子郵件。

想要這樣做嗎?獲取你自己的服務器。並期望電子郵件只是去他們所屬的地方 - 垃圾桶。

+4

不如他們希望用戶「不能關閉窗口或離開我的頁面」的問題。 –

0

所有你所要做的就是改變從地址就像在你的代碼:圍繞

Msg.From = "anyNameIWant" 

你將需要從不同的服務等,然後Gmail發送,和幾乎每一個電子郵件服務如果發件人的地址與實際發件人的地址不符,則會將此電子郵件正確地轉化爲垃圾郵件。

但是,只是假設,假設你有你自己的電子郵件服務器設置,並寫電子郵件給自己的員工,並希望從地址更改,但不能更改域@myurl.com那麼你很可能得到的是工作

0

一般而言,您可以製作From電子郵件,無論您想要什麼。收件人仍然能夠看到服務器的來源。在發送通知等時,我經常會發出類似「[email protected]」的地址。這樣用戶很清楚他們不應該回復。

相關問題