2012-07-18 51 views
2

我正在一個在線系統,我有多個客戶端,我的客戶有多個聯繫人。現在,我希望我的客戶能夠發送電子郵件給他的聯繫人,所以當他的聯繫人收到一封電子郵件時,他們會在該字段中看到他的公司名稱和他的電子郵件地址來自:[email protected] & ABC公司。從MVC C#發送電子郵件與多個字段

我使用MVCMailer發送電子郵件,它的工作原理非常完美,但是當我收到測試電子郵件時,而不是我的客戶電子郵件地址(TO和NAME)中顯示的是我在web.config文件中配置的電子郵件地址。如何更改發件人地址,以便我的客戶的聯繫人可以看到他的電子郵件地址不是我的?

==========================

<system.net> 
    <mailSettings> 
     <!-- Method#1: Configure smtp server credentials --> 
    <smtp from="[email protected]"> 
    <network enableSsl="true" host="smtp.xyz.com" port="587" userName="[email protected]" password="ABC" /> 
    </smtp> 
    <!-- Method#2: Dump emails to a local directory --> 
    <!-- 
    <smtp from="[email protected]" deliveryMethod="SpecifiedPickupDirectory"> 
    <network host="localhost" /> 
    <specifiedPickupDirectory pickupDirectoryLocation="c:\temp\"/> 
    </smtp> 
    --> 
</mailSettings> 

============= ==========================

這是我正在使用C#類

var mailMessage = new MailMessage { Subject = eSubject }; 
     mailMessage.To.Add(Email); 
     mailMessage.Bcc.Add("[email protected]"); 
     mailMessage.ReplyToList.Add(new MailAddress(From, ContactPerson)); 
     mailMessage.Sender = new MailAddress("[email protected]", ContactPerson); 

     //mailMessage.To.Add("[email protected]"); 
     //ViewBag.Data = someObject; 
     ViewData = new ViewDataDictionary(obj); 


     SmtpClient smtp = new SmtpClient("192.168.1.2",25); 
     smtp.Credentials = new NetworkCredential("[email protected]", "test"); 

     smtp.Send("[email protected]","[email protected]","test","test"); 
     PopulateBody(mailMessage, viewName, null); 


     SmtpClient smtp = new SmtpClient("192.168.1.2",25); 
     smtp.Credentials = new NetworkCredential("[email protected]", "test"); 

     //smtp.Send("[email protected]","[email protected]","test","test"); 
     PopulateBody(mailMessage, viewName, null); 

     return mailMessage; 

代碼=== =====================

請告訴我如何解決這個問題,甚至可能或n ot與mvc c#?

Riyasat

+1

您是否嘗試過使用MailMessage的過載的ctor來接受「from」和「to」電子郵件地址? http://msdn.microsoft.com/en-us/library/14k9fb7t.aspx – devlife 2012-07-18 00:54:23

+0

@tereško否我沒有檢查過。我會檢查它,並會更新,如果可以使它的工作。 – Riy 2012-07-18 07:22:02

回答

0

看看你的代碼:

mailMessage.Sender = new MailAddress("[email protected]", ContactPerson); 

smtp.Send("[email protected]","[email protected]","test","test"); 

我想,這裏到處都是你告訴MvcMailer你的發件人是 「[email protected]」。我想在這裏你應該改變你的客戶電子郵件和名稱。
順便說一句,檢查「smtp.Send」的評論。確保你知道所有參數的含義。

+0

感謝您的回覆,我認爲在web.config文件中輸入了錯誤的電子郵件地址,這造成了混淆。在我的web.config文件中,我有[email protected]電子郵件地址而不是[email protected]從部分的SMTP。 現在,當我發送電子郵件時,我希望看到它來自[email protected],而不是來自[email protected]電子郵件地址,但這並未發生,當然我知道Send()函數的參數:p。現在,你可以通過一些光線,我做錯了什麼,我如何實現所需的功能。謝謝 – Riy 2012-07-18 07:17:30