2

I am making an online system where I have multiple clients and my clients have multiple contacts. Now I want my client to be able to send emails to his contacts, so when his contact gets an email they see his company name and his email address in the field From:abc@abc.com & ABC company.

I am using MVCMailer to send emails it works perfect but when I receive test email, then instead of my clients email address in (TO and NAME) it shows me the email I configured in web.config file. How can I change From address so that my client's contacts can see his email address not mine ?

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

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

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

This is the code I am using in C# class

   var mailMessage = new MailMessage { Subject = eSubject };
        mailMessage.To.Add(Email);
        mailMessage.Bcc.Add("xyz@xyz.com");
        mailMessage.ReplyToList.Add( new MailAddress(From, ContactPerson));
        mailMessage.Sender = new MailAddress("xyz@xyz.com", ContactPerson);

        //mailMessage.To.Add("some-email@example.com");
        //ViewBag.Data = someObject;
        ViewData = new ViewDataDictionary(obj);


        SmtpClient smtp = new SmtpClient("192.168.1.2",25);
        smtp.Credentials = new NetworkCredential("xyz@xyz.com", "test");

        smtp.Send("xyz@xyz.com","xyz@xyz.com","test","test");
        PopulateBody(mailMessage, viewName, null);


        SmtpClient smtp = new SmtpClient("192.168.1.2",25);
        smtp.Credentials = new NetworkCredential("xyz@xyz.com", "test");

        //smtp.Send("xyz@xyz.com","xyz@xyz.com","test","test");
        PopulateBody(mailMessage, viewName, null);

        return mailMessage;

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

Please tell me how can I fix this problem or even is it possible or not with mvc c#?

Riyasat

tereško
  • 58,060
  • 25
  • 98
  • 150
Riy
  • 479
  • 1
  • 8
  • 16
  • 1
    Have you tried using the overloaded ctor of MailMessage that accepts a "from" and "to" email address? http://msdn.microsoft.com/en-us/library/14k9fb7t.aspx – devlife Jul 18 '12 at 00:54
  • @tereško No I have not checked that. I will check it and will update if can make it work with that. – Riy Jul 18 '12 at 07:22

1 Answers1

0

Look at your code:

mailMessage.Sender = new MailAddress("xyz@xyz.com", ContactPerson);

smtp.Send("xyz@xyz.com","xyz@xyz.com","test","test");

I think everywhere here you told the MvcMailer that your sender is "xyz@xyz.com". I think here you should change to your client email and name.
BTW, check the comment of "smtp.Send". Make sure you know all the parameters meaning.

Coofucoo
  • 119
  • 7