我正在一個在線系統,我有多個客戶端,我的客戶有多個聯繫人。現在,我希望我的客戶能夠發送電子郵件給他的聯繫人,所以當他的聯繫人收到一封電子郵件時,他們會在該字段中看到他的公司名稱和他的電子郵件地址來自:[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
您是否嘗試過使用MailMessage的過載的ctor來接受「from」和「to」電子郵件地址? http://msdn.microsoft.com/en-us/library/14k9fb7t.aspx – devlife 2012-07-18 00:54:23
@tereško否我沒有檢查過。我會檢查它,並會更新,如果可以使它的工作。 – Riy 2012-07-18 07:22:02