Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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]) + ";";                                    
    if(!string.IsNullOrEmpty(fromEmailAddresss))
        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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.To.Add("somemone@company");
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");
smtp.Send(message);
share|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 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 at 9:46
    
Thanks a lot sir, it worked perfectly –  users1100 May 7 at 9:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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