Code to Create Custom E-mail of Specific Form Data

K

Keith

Okay, I've been looking all over for an answer to this mystery of mine, and
figured someone here could get me started.

I've got several forms going in Infopath, reading/writing data to and from
both Sharepoint and SQL DB's, but I am having the darndest time trying to
figure out how to send out a customized e-mail.

I do realize that InfoPath can send out an attachment, but that is not what
I want to accomplish here.....I want to send the body of the e-mail out in a
message (without manually having to go to File > Send To, etc.)....That said,
I realize it needs to be coded, but I've had no luck getting that going on my
own (my apologies, I am far from being a developer, just an Admin who
adminsters Sharepoint along with the rest of my Microsoft Infrastructure!!!)..

If anyone can post a few snippets of code, I can get it going from there,
just looking for some guidance on how to get going...Ideally, I would like to
automatically send the form like it is delivered by manually going to File >
Send To, etc....but I'll settle for reading the data in the fields into the
body of a message built in code....

Thanks in advance...
 
K

Keith

Frank, thanks for getting back with me on this so quickly!!!

I looked at the link ending in 694, and haven't gone anywhere with that...It
may be something, but I'm really working the e-mail route....
So, I like where I'm going with the other link you posted (293), but am
running into a couple of problems. To be clear, this form is created with
InfoPath SP1 in case that helps...

1. When I click the button, the first notification I get reads:
"An ActiveX control on this page might be unsafe to interact........."
2. Then I get a pop-up from Outlook:
"A program is trying to automatically send e-mail on your behalf, do you
want to allow this...."
3. And lastly, I get the e-mail, but it is all the XML, not formatted as
desired.

I'm using this code:
/*------------------------------------------------------------------------------
Automatic mail function
------------------------------------------------------------------------------*/

function mailMessage(to,subject,cc,body,bcc){
try
{
var myOlApp = new ActiveXObject("Outlook.Application");
newMail = myOlApp.CreateItem(0);
newMail.To = to;
newMail.Subject = subject;
newMail.CC = cc;
newMail.BCC = bcc;
newMail.Body = body;
// if you want to see the e-mail b4 sending use
//newMail.Display(0);
//If you want to send automatically use:
newMail.Send();
}
catch(ex)
{
XDocument.UI.Alert(ex.description);
}
}

Is there a way to either prevent the interaction with the pop-ups, or
somehow build a formatted e-mail (using the fields)...I think that is where
I'm going to get what I want, problem is a I'm a real novice with JScript...

You know us admins only know VBScript, and even then, it's a stretch!!!!

Thanks for the help and any info!!
 
K

Keith

OK, I got something working using the following code:

function CTRL19_5::OnClick(eventObj)
{
// Create a new message and fill all its fields
var iMsg = new ActiveXObject("CDO.Message");
iMsg.To = "(e-mail address removed)";
iMsg.From = "(e-mail address removed)";
iMsg.Subject = XDocument.DOM.selectSingleNode("//my:description").text;
iMsg.TextBody = XDocument.DOM.selectSingleNode("//my:dateOccur").text;

// Set SMTP server
iMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailrelay.testmail.com";
// Use the SMTP over the netowrk for sending method
iMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2;
// Make persistent
iMsg.Configuration.Fields.Update();

// Send the message
iMsg.Send();
}

Now the million dollar questions, to finally solve this....

1. How do you prevent the ActiveX pop-up in InfoPath

2. The big one....How do I ready multiple fields into the "iMsg.TextBody"
part (the body of the e-mail....The code above pulls one field out of my form
into the e-mail, now I want to build a formatted e-mail....I know how to do
this in VBScript, but I'm struggling with the JScript (and my code needs to
be in JScript because of other code doing things)

I'm just about there, just need the push over the edge!!!
 
F

Franck Dauché

Hi Keith,

1. Is your form fully trusted? Needs to be because of the ActiveXObject call
2. You can build a string before assigning it to iMsg.TextBody.
var s = XDocument.DOM.selectSingleNode("//my:field1").text + " " +
XDocument.DOM.selectSingleNode("//my:field2").text
you can format with escape sequences
(http://www.functionx.com/jscript/Lesson01.htm).

Hope that it helps.

Regards,

Franck Dauché
 
F

Franck Dauché

You are welcome Keith.

If any post in that thread was useful to you, don't hesitate to rate it so
that others find answers quickly.

Cheers and good luck with your InfoPath developments...

Franck Dauché
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top