Tuesday, July 22, 2008

EmailSubmitConnection :How to add custom email to an InfoPath email data connection EmailSubmitConnection

EmailSubmitConnection : Often times I need to add some more information to an email that is sent from InfoPath besides just a view of the form. Sometimes I want to add fields and such to the body of the email but just end up adding the fields to the subject line since there is no way without writing code to include fields in the introduction field of the email. I hope with Office 14 they make this possible without writing code, but for right now let's see how to do it.

First, you need to create a data connection (EmailSubmitConnection) that sends an email to someone within the InfoPath data connections. This data connection needs to be created so we can reference it in our code.

Second get into the code behind of the form, I'm using C# for InfoPath 2007 so those with InfoPath 2003 may have to figure this out for themselves but hopefully this gives them some clues.

Within, probably a button click event, I get a reference to the email data connection. The "email connection" is the name of the data connection I created in the first step.

EmailSubmitConnection emailDataConnection = (EmailSubmitConnection)this.DataConnections["email connection"];

//add your custom message to the introduction, say hello to yourself
XPathNavigator xnDoc = this.MainDataSource.CreateNavigator();
XPathNavigator fullName = xnDoc.SelectSingleNode("my:myFields/my:txtFullName", this.NamespaceManager);
emailDataConnection .Introduction = "My custom introduction with some fields. Hello " + fullName.Value;

//submit the data connection which sends the email
emailDataConnection .Execute();

As you can see, just get a reference to the data connection (EmailSubmitConnection), set the Introduction property and execute. This can also be accomplished for the FileSubmitConnection and WebServiceConnection objects, so you can write code to execute these connections and set some custom properties before making the submit. Hope this helps someone.

6 comments:

electronic signatures said...

As you stated, I also need to add some more information to an email that is sent from InfoPath besides just a view of the form.But i dont know why i am unable to create a data connection.It may be problem due to slow speed of internet or may be something else

Anonymous said...

Right away I am going to do my breakfast, later than having my breakfast coming over again to read further news.
Have a look at my webpage ... ncesc.com

Anonymous said...

Wow that was strange. I just wrote an incredibly long comment but after I clicked submit my
comment didn't appear. Grrrr... well I'm not writing all that over
again. Regardless, just wanted to say wonderful blog!


Have a look at my webpage ... .UTTVLzDqh8E

Anonymous said...

I create a comment when I especially enjoy a article on a blog or if I have something to valuable to
contribute to the discussion. It is caused by the sincerness communicated in the post I looked at.

And on this article "EmailSubmitConnection :How to add custom email to an InfoPath email data connection EmailSubmitConnection".
I was moved enough to write a thought :-P I do have a few questions for you if it's allright. Could it be only me or do a few of the responses appear like written by brain dead folks? :-P And, if you are writing at other sites, I would like to follow anything new you have to post. Would you make a list every one of all your community pages like your linkedin profile, Facebook page or twitter feed?

Here is my web-site ... Spazio Kovan

Anonymous said...

What a information of un-ambiguity and preserveness of valuable
familiarity concerning unexpected feelings.

Feel free to surf to my homepage ... juegosparapc10

Anonymous said...

What's up to every body, it's my first pay a quick visit of this webpage;
this web site carries remarkable and truly excellent material in favor
of readers.

Check out my blog post :: Free Teen Sex