How to change email address from address field?

I tried to change the FROM field with the name and email address. But when I receive the email, it is shown below

My network <commity@company.com [My network <commity@company.com]

Mycode is similar to below

    const string from = "My network <commity@company.com>";

    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 the FROM email address to be displayed as below

My network [commity@company.com]
+3
source share
3 answers

SPUtility.SendMail will always use the smtp address, as indicated in Central Administration> Outgoing Email Settings, and the friendly name is the name 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("me@mycompany.com", "Steve James" );
mail.To.Add("you@yourcompany.com");

//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);
+3
source

, , , - , , , SPUtility.SendMail, , :

const string from = "\"My network\" <commity@company.com>";
+2

I believe that if you look at the mail object in the .NET Framework, you can do what you want.

Perhaps this site can help you in the future?

+1
source

Source: https://habr.com/ru/post/1766095/


All Articles