Send Via Email Using Code - InfoPath Dev
in

InfoPath Dev

Send Via Email Using Code

Last post 03-16-2007 09:48 AM by nlefaivre. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-15-2007 11:52 AM

    Send Via Email Using Code

    Hi There,

    I am working on some forms for our firm. I am currently working on our vacation request form. I would like to automate it so that once the staff member fills in their portion, they can email it to their supervisor. The supervisor in turn will fill in their portion and then forward it on to HR.

    The submit to HR is easy as it is always the same address so I was able to use the "Submit" feature on the button control.

    What I would like to do now is add a second button after the staff section that would email the form to their supervisor. I would like them to click the button, and a new email message would open up with the form attached. This would allow users to email a variety of staff members at a time. As each staff member potentially has a different lawyer or supervisor they need to be able to access the outlook addresses.

    Can anyone help me out with this?

    Thanks!
    Ropegun
  • 03-15-2007 11:05 PM In reply to

    Re: Send Via Email Using Code

    For your custom mail you can use this code behind your button:

    MailEnvelope objMail = thisApplication.ActiveWindow.MailEnvelope;
    objMail.To = "";
    objMail.CC = "";
    objMail.Subject = "";
    objMail.Visible = true;


    You can use below class to pass either the users login (samacountname) name, real name (name) or eMail (mail) and retrieve the corresponding manager from active directory. like this you can auto populate the objMail.To already with the manager of the requestor.

    using System;
    using System.Text;
    using System.DirectoryServices;
    using System.Collections;

    namespace YourNameSpace
    {
    /// <summary>
    /// Summary description for AD_Helper.
    /// </summary>
    public class AD_Helper
    {
    string var;

    public AD_Helper()
    {
    }
    //1 parameter: what do you path (name, mail etc.), 2nd actual value, third what to you want, so if I liked to get my manager assuming that nukkumatti is my login name I had to call the method like getProperties("samaccountname", nukkumatti, "manager").

    public string getProperties(string criteria, string givenValue, string searchValue)
    {
    try
    {
    // Create a directory searcher on the path provided when created the instance
    DirectoryEntry entry = new DirectoryEntry("LDAP://OU=Husky Users,DC=corp,DC=huskyims,DC=com");
    DirectorySearcher searcher = new DirectorySearcher(entry);

    string ToFind = "(" + criteria +"=" + givenValue + ")";
    searcher.Filter = ToFind;

    // Try to find the employee
    SearchResult result = searcher.FindOne();
    if (result != null)
    {
    // Get the 'DirectoryEntry' that corresponds to 'result'.
    DirectoryEntry myDirectoryEntry = result.GetDirectoryEntry();

    // Get the properties of the 'mySearchResult'.
    ResultPropertyCollection myResultPropColl;
    myResultPropColl = result.Properties;

    foreach(Object myCollection in myResultPropColl[searchValue])
    {
    var = myCollection.ToString();
    }
    }
    }
    catch (Exception ex)
    {
    ex.Message.ToString();
    }
    return var;
    }
    }
    }
    Listen to Motörhead cos they play Rock'n Roll :)
  • 03-16-2007 09:48 AM In reply to

    Re: Send Via Email Using Code

    Hi nukkumatti,

    I know this will sound lame, but I am sooo new at this that I need to ask you a couple more questions.

    Programming is not my strong area so - I have put a button on my form, I have set it to use rules or code. I get to the JS code page and where it says "Write code here" I have copied the first section of code you sent me.

    I save this and then preview my form and get an error message related back to the code.

    So, does the code have to go somewhere specific, did I miss a step?

    I would be so appreciative of any help I can get. Sorry as this is probably such an easy task but this is my first crack at this and I am at a loss.

    Thanks!
    Nathalie
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.