Submitting as email question - InfoPath Dev
in

InfoPath Dev

Submitting as email question

Last post 02-19-2008 05:31 AM by zeroecho. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 10-30-2007 10:45 AM

    Submitting as email question

    Hello all

    currently I am  using infopath 2003. I have created a form that when the submit button is selected it will email the form out as an attachment. this all works well. some of my users do not have access to send email (no email account). I was wondering if there is any way to code the smtp info in to the form so even if you where not email enabled (ie:Outlook)it would still send the email?

  • 10-30-2007 11:32 AM In reply to

    Re: Submitting as email question

    Hi

    I have not treid this personally but it would be possile in managed code.  I googled the question to find the following:

    Sending Email From InfoPath Using Managed Code

    It is possible to send an email from InfoPath when a form is submitted. Just add a new data connection and select "Email message" as your data submission method. You can also send email from InfoPath using managed code. You must have InfoPath toolkit installed on your machine in order to write managed code for InfoPath forms.

    Ref: http://www.sharepointblogs.com/ssa/archive/2006/05/01/6186.aspx

    Direct link to download toolkit: http://www.microsoft.com/downloads/details.aspx?familyid=7E9EBC57-E115-4CAC-9986-A712E22879BB&displaylang=en also dowqnloadable for InfoPath 2007 http://www.microsoft.com/downloads/details.aspx?FamilyID=00779894-e95f-4b22-8590-07584c891207&DisplayLang=en

    1. Open your form in design mode and add a button to it.
    2. Double click the button and select "Edit Form Code..." from the dialog box that pops up. This will open a Visual Studio editor. Add following code in button's OnClick() event:

    [InfoPathEventHandler(MatchPath="CTRL1_1", EventType=InfoPathEventType.OnClick)]
    public void CTRL1_1_OnClick(DocActionEvent e)
    {

    MailMessage MailMsg = new MailMessage();
    MailMsg.Body = "This is a test message and currently logged in user is " + System.Environment.UserName;
    MailMsg.From = "[email protected]";
    MailMsg.To = "[email protected]";
    MailMsg.Subject = "InfoPath Test Message";

    SmtpMail.SmtpServer = "smtp.yourdomain.com";
    SmtpMail.Send(MailMsg);

    }

    I think this should help you

    Cheers

    Adam Harding
    Wales
    UK
  • 10-30-2007 12:32 PM In reply to

    Re: Submitting as email question

    thanks I will give it a try

  • 10-30-2007 01:15 PM In reply to

    Re: Submitting as email question

    Cool

    Let me know how it goes.

    One other thing, as these users do not have Outlook, do they have Infopath installed?

    Cheers

    Adam Harding
    Wales
    UK
  • 02-19-2008 05:31 AM In reply to

    • zeroecho
    • Top 500 Contributor
      Male
    • Joined on 10-23-2007
    • Yorkshire, UK
    • Posts 39

    Re: Submitting as email question

    Does anyone know the C# code to attach the current InfoPath document to the email using this (or the newer System.Net.Mail.MailMsg option)

    Basically got code like this

    System.Net.Mail.MailMessage MailMsg = new System.Net.Mail.MailMessage();

    MailAddress sentfrom = new MailAddress(System.Environment.UserName + "@companyname." + domainvalue);

    MailMsg.To.Add(domNav.SelectSingleNode("/my:TimesheetDetails/my:Department", NamespaceManager).Value + "manager@companyname." + domainvalue);

    MailMsg.From = sentfrom;

    MailMsg.Subject =
    "Timesheet approval form from " + domNav.SelectSingleNode("/my:TimesheetDetails/my:EmployeeInformation/my:EmployeeName", NamespaceManager).Value;

    SmtpClient sendmail = new SmtpClient();

    sendmail.Host = "hostname";

    sendmail.Send(MailMsg);

    Basically I've created a "Submit for approval" button on my form which I then want to email to the department manager, using InfoPath 2007 client (using the DataConnections["Email Submit"].Execute command) this works fine, but using Browser based forms I get a error and the mail server is set up correctly on our MOSS server.

    My other option is using workflows on the timesheet but I figured this way should be achievable - just can't find the right command to attach the view that InfoPath manages to create.

    Thanks

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