none
How to use SPUtility.SendEmail RRS feed

  • Question

  • Hi,

    I used this code to send an e-mail and it works perfectly :

    StringDictionary headers = new StringDictionary();
    
        headers.Add("to", String.Format("{0}",
    
           
    
           to
    
           ));
    
        headers.Add("cc", String.Format("{0}",
    
           
    
           cc
    
           ));
    
        headers.Add("from", String.Format("{0}",
    
           
    
           from
    
           ));
    
        headers.Add("subject", subject);
    
        headers.Add("content-type", "text/html"); //This is the default type, so isn't neccessary.
    
    
    
        string bodyText = body;
    
    
    
        SPUtility.SendEmail(SPContext.Current.Web, headers, bodyText);
    
    

    My question is : How can I format the sender/receiver e-mail : for example FirstName LastName <mail@company.com>.

    The goal of this formatting is the show the name (not the mail) in the recipient when we send an e-mail.

    Best regards


    Wednesday, May 18, 2011 4:00 PM

Answers

  • Hi zemzemi,

     

    For your issue, I know you want to format the sender/receiver e-mail to display name instead of email address. Unfortunately, it has nothing to do with SPUtility.SendEmail but Exchange server. The only responsibility of SPUtility.SendEmail() method is to send Email.

    More information:

    http://support.microsoft.com/kb/831124

     

    Thanks,

    Porter Wang

    • Marked as answer by KeFang Chen Monday, May 23, 2011 1:22 AM
    Friday, May 20, 2011 2:55 AM

All replies

  • Hi zemzemi,

     

    For your issue, I know you want to format the sender/receiver e-mail to display name instead of email address. Unfortunately, it has nothing to do with SPUtility.SendEmail but Exchange server. The only responsibility of SPUtility.SendEmail() method is to send Email.

    More information:

    http://support.microsoft.com/kb/831124

     

    Thanks,

    Porter Wang

    • Marked as answer by KeFang Chen Monday, May 23, 2011 1:22 AM
    Friday, May 20, 2011 2:55 AM
  • Hi,

    Thank you for your answer, but I think with Asp.Net we can add company name to e-mail.

     

    Best regards

    Friday, May 20, 2011 7:31 AM
  • Did you try to set the from header like this "Anders Runge <anders@company.com>" ?
    Friday, May 20, 2011 8:12 AM
  • Yes, I tried and it works only with "From" attribute but with "cc" and "to" the behaviours is stange !
    Friday, May 20, 2011 8:26 AM
  • Well it looks like the SendEmail on SPUtility dosn't support that. At least I couldn't get it to work. However if you send the email using SmtpClient it works :

    MailMessage message = new MailMessage("sender@mycompany.com", recipient@mycompany.com);

    message.Body = "Hello";

    message.CC.Add(new MailAddress("carboncopy@mycompany.com", "Carbon Copy Display Name");

    SmtpClient client = new SmtpClient(SPContext.Current.WebApplication.OutboundMailServiceInstance.Server.Address);

    client.Send(message);  

    Monday, May 23, 2011 9:27 AM