none
Infopath Form - Change "From" address based on form data

    Question

  • I have a Infopath form published to a form library on Sharepoint 2013. I have it set for browser submission to an email address. The problem is that the "from" address is always the SMTP address setup on the Sharepoint site. I would like the "from" address to change based on the contents of the "email" field on the form. I see this is easy to do to modify the "to" addresses but not the "from". Thanks in advance.
    Monday, August 04, 2014 9:31 PM

Answers

  • Hi Josh,

    We can't do it dynamically for browser based forms without writing some code there is not a way to customize the From email Address in Infopath but we can write code on submit button or any other events to send the email where you can specify your own from email address like this.

    Use System.Net.Mail classes to send email in InfoPath

    using System.Net.Mail;

    Add the following C# code to the Clicked event handler for the button:

    XPathNavigator root = MainDataSource.CreateNavigator();

    string toAddress = root.SelectSingleNode("//my:toAddress",    NamespaceManager).Value;

    string fromAddress = root.SelectSingleNode("//my:fromAddress",   NamespaceManager).Value; string subject = root.SelectSingleNode("//my:subject",   NamespaceManager).Value;

    string body = root.SelectSingleNode("//my:body",   NamespaceManager).Value; using (MailMessage msg = new MailMessage(fromAddress, toAddress)) {   msg.Subject = subject;  

     msg.Body = body;   msg.IsBodyHtml = false;  

     SmtpClient smtp = new SmtpClient("<your_smtp_server_name>");   smtp.Send(msg);

    }

    Even If we would use SPUtility.SendMail to send email in InfoPath here also we can’t change the from email Address, Please let me know if you need further help to implement this or any query.


    Krishana Kumar http://www.mosstechnet-kk.com


    Friday, August 08, 2014 10:34 PM

All replies

  • Hi Josh,

    According to your description, my understanding is that you want to change the From email address when submitting the form as an email.

    Per my knowledge, there is no OOB way to change the From email address when submitting the form as an email.

    Because the email address is pre-defined in SharePoint and SharePoint uses the outgoing email address for sending all outgoing emails.

    If you want to change the email address, you need to create custom solution which is not easy.

    Best regards.

    Thanks

    Victoria Xia
    TechNet Community Support

    Wednesday, August 06, 2014 2:47 AM
    Moderator
  • Any other ideas on this? I need to have the from address dynamically change based on who completes the form.
    Thursday, August 07, 2014 3:55 PM
  • Hi Josh,

    We can't do it dynamically for browser based forms without writing some code there is not a way to customize the From email Address in Infopath but we can write code on submit button or any other events to send the email where you can specify your own from email address like this.

    Use System.Net.Mail classes to send email in InfoPath

    using System.Net.Mail;

    Add the following C# code to the Clicked event handler for the button:

    XPathNavigator root = MainDataSource.CreateNavigator();

    string toAddress = root.SelectSingleNode("//my:toAddress",    NamespaceManager).Value;

    string fromAddress = root.SelectSingleNode("//my:fromAddress",   NamespaceManager).Value; string subject = root.SelectSingleNode("//my:subject",   NamespaceManager).Value;

    string body = root.SelectSingleNode("//my:body",   NamespaceManager).Value; using (MailMessage msg = new MailMessage(fromAddress, toAddress)) {   msg.Subject = subject;  

     msg.Body = body;   msg.IsBodyHtml = false;  

     SmtpClient smtp = new SmtpClient("<your_smtp_server_name>");   smtp.Send(msg);

    }

    Even If we would use SPUtility.SendMail to send email in InfoPath here also we can’t change the from email Address, Please let me know if you need further help to implement this or any query.


    Krishana Kumar http://www.mosstechnet-kk.com


    Friday, August 08, 2014 10:34 PM