I have created a custom action through which I am sending the email to the selected contact items from the contacts list.

I have used SPUtility.SendEmail() method to send mail. To show other than central admin's email id to the receiver of the email I have set the from attribute of the Email header in the code like below,

if (currentItem != null)
    header = new StringDictionary();
    header.Add("to", Convert.ToString(currentItem[SPBuiltInFieldId.EMail]));
    header.Add("subject", emailSub);
    header.Add("content-type", "text/html");
    logMailTo += Convert.ToString(currentItem[SPBuiltInFieldId.EMail]) + ";";                                    
        header.Add("from", fromEmailAddresss); // here for example I have set yyy@abc.com that will be visible to the receiver of email.
    SPUtility.SendEmail(SPContext.Current.Web, header, emailBody);

There is scenario for example, I have set the outgoing email in the central admin is : xxx@abc.com and I have set the from attribute to yyy@abc.com, when user receives the email from yyy@abc.com and click on Reply from the outlook then "to" field in the outlook displays the xxx@abc.com

I want to set such a thing that when user replies to the email received from yyy@abc.com then it should display same email.

What should I do?


Have you tried adding a "replyto" header as well?

header.Add("replyto", fromEmailAddress);

It should make sure users get the correct address when they reply to the email.

If that does not work you might be out of luck with the SPUtility and have you use the "normal" C# way (you will need the address to your SMPT host):

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.Subject = "The subject";
message.From = new System.Net.Mail.MailAddress("hej@robert-lindgren.se");
message.Body = "Tra la la";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("Address to your SMPT server");
| improve this answer | |
  • thanks for answering sir I tried your way but not working. it displays the email address of central admin instead header.add("replyto",fromEmailAddress); – users1100 May 7 '14 at 9:42
  • Even with both headers? In that case you should probably use the HttpUtility, since you are not using the SharePoint address anyway, will update my post – Robert Lindgren May 7 '14 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.