none
Send email as current user?

    Question

  • When sending an email from Sharepoint the email's From: address is always what you set in the site settings.  Is there a way to ensure an email is sent from the user and not from this email address?

    I'm creating a form and wanted it to send an email but it needs to look like it's coming from the user who created the form.

    Thursday, February 25, 2010 9:54 PM

Answers

  • StringDictionary headers = new StringDictionary();
    
    headers.add("to",someone@somewhere.com);
    headers.add("cc",someone.else@somewhere.com);
    headers.add("bcc",somebody@somewhere.com);
    headers.add("from",sender@somewhere.com);
    headers.add("subject","SPUtility.SendEmail with headers test");
    string bodyText ="Email body";
    
    SPUtility.SendEmail(web, headers, bodyText);

    from email you can replace with value from SPContext.Current.Web.CurrentUser.Email
    Thursday, February 25, 2010 10:02 PM

All replies

  • StringDictionary headers = new StringDictionary();
    
    headers.add("to",someone@somewhere.com);
    headers.add("cc",someone.else@somewhere.com);
    headers.add("bcc",somebody@somewhere.com);
    headers.add("from",sender@somewhere.com);
    headers.add("subject","SPUtility.SendEmail with headers test");
    string bodyText ="Email body";
    
    SPUtility.SendEmail(web, headers, bodyText);

    from email you can replace with value from SPContext.Current.Web.CurrentUser.Email
    Thursday, February 25, 2010 10:02 PM
  • This something I would have to compile right?  Is there a way to place this in the form with straight sharepoint or Designer?

    I was trying to use the Workflow designer as well but couldn't get very far.

    Friday, February 26, 2010 2:57 PM
  • Yes it is a C# code. I think you haven't alternatives for this.
    Friday, February 26, 2010 3:03 PM
  • David, i want to ask you about exact email place you are asking for. On a list item creation etc, sharepoint sends email. If you are talking about a different place, please mention the exact place. To override the email functionality, you will have to write the code as mentioned by Jevegni,
    Moonis Tahir MVP, MCPD, MCSD.net, MCTS BizTalk 2006/SQL 2005/SharePoint Server 2007 (Dev & Config)
    Friday, February 26, 2010 3:59 PM
  • That's what I thought.  Thanks for the help.

    Friday, February 26, 2010 4:19 PM