views:

47

answers:

2

I was trying to change FROM field with Name and Email address. But When I get email It is comaing like below

My network <[email protected] [My network <[email protected]]

Mycode is like below

    const string from = "My network <[email protected]>";

    StringDictionary headers = new StringDictionary();
       headers.Add("to", invitee.userEmail);
       headers.Add("subject", ltEmailSubject.Text);
       headers.Add("from", from);
       headers.Add("content-type", MediaTypeNames.Text.Html);

       _emailSuccessful = SPUtility.SendEmail(elevatedSite.RootWeb, headers,
                          emailBody + Environment.NewLine + "");

I want FROM email address should showup like below

My network [[email protected]]
+1  A: 

I believe if you look at the mail object in the .Net Framework, you could do what you wish to do.

Maybe this site could help you out further?

Richard B
A: 

SPUtility.SendMail will always use the from smtp address as specified in Central Administration > Outgoing Email Settings and the friendly name is set to the title of the site.

Instead you can use (from http://www.systemnetmail.com/faq/3.2.1.aspx)

MailMessage mail = new MailMessage();

//set the addresses
//to specify a friendly 'from' name, we use a different ctor
mail.From = new MailAddress("[email protected]", "Steve James" );
mail.To.Add("[email protected]");

//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";

//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
Ryan