Send a mail with button action from infopath form (through managed code) - InfoPath Dev
in

InfoPath Dev

Send a mail with button action from infopath form (through managed code)

Last post 02-21-2010 12:36 PM by Karsten Brocksieper. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 02-19-2010 10:37 PM

    Send a mail with button action from infopath form (through managed code)

    Hi;

     I'm trying send a mail from my infopath form with button action... It seems the code is very easy but when I debug I got and error message at the end of code block  SmtpMail.Send(mail);

     Error or Warning Message is :

     

    System.Web.HttpException was unhandled by user code

      Message="The transport failed to connect to the server.\r\n"

      Source="System.Web"

      ErrorCode=-2147467259

      StackTrace:

           at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)

           at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message)

           at System.Web.Mail.SmtpMail.Send(MailMessage message)

           at Aktiviteler.FormCode.CTRL68_5_Clicked(Object sender, ClickedEventArgs e) in D:\My Documents\InfoPath Projects\Aktiviteler5\FormCode.cs:line 45

           at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)

           at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

     

     

    Here's my code :

      

     

    using Microsoft.Office.InfoPath;

    using System;

    using System.Xml;

    using System.Xml.XPath;

    using System.Web.Mail;

    using Microsoft.Office.Interop.Outlook;  

     

    namespace Aktiviteler

    {

        public partial class FormCode

        {

            public void InternalStartup()

            {

                ((ButtonEvent)EventManager.ControlEvents["CTRL68_5"]).Clicked += new ClickedEventHandler(CTRL68_5_Clicked);

            }

     

            public void CTRL68_5_Clicked(object sender, ClickedEventArgs e)

            {

                MailMessage mail = new MailMessage();

                          

                mail.To = "[email protected]";

                mail.From = "[email protected]";

                mail.Subject = "this is a test email.";

                mail.Body = "this is my test email body";

                SmtpMail.SmtpServer = "bhldscas1.internal.borusan.com"; 

                

                SmtpMail.Send(mail);

           

            }

        }

    }

           Where I make a mistake? And could help me about the solution...Thanks

  • 02-19-2010 10:57 PM In reply to

    Re: Send a mail with button action from infopath form (through managed code)

    Make sure that in form options you have selected Full trust option in Scurity tab.Try Again after that..

    Vishal Srivastava
    Senior Software Engineer
    SDG Software Pvt Ltd
  • 02-20-2010 02:45 AM In reply to

    Re: Send a mail with button action from infopath form (through managed code)

    I already did it.Nothing is changed , I've still the same problem :(

  • 02-20-2010 07:46 AM In reply to

    Re: Send a mail with button action from infopath form (through managed code)

     Could it be that the SMTP server bhldscas1.internal.borusan.com isn't accessible from the machine where you're testing this form?  You can determine if that's the case by doing a ping from the Windows command line.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-20-2010 10:32 PM In reply to

    Re: Send a mail with button action from infopath form (through managed code)

    I cant ping to the SMTP server and also I can send email from command line .. :(

  • 02-21-2010 09:07 AM In reply to

    Re: Send a mail with button action from infopath form (through managed code)

     If you can't ping the server we can't do much to solve that for you.  It sounds like the SMTP server is somewhere on your company intranet that's not accessible from your machine.  Perhaps you need to connect to the network by VPN, or develop your form using a machine that's connected to the network.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-21-2010 12:36 PM In reply to

    Re: Send a mail with button action from infopath form (through managed code)

    Hi, 

    your error is definitely a network related error. Your application cannot connect to the mail server specified --- so you have to check:

    • Is a valid SMTP Server
    • Check to be sure the server System.Web.Mail is executing on can connect to the mail server. Some times firewalls or proxy servers can get in the way.
    • Try specifying the value by IP address. Poor DNS resolution can sometimes hinder name lookups.
    • Make sure the that the mail server is running at port 25.
    • For testing purposes change the MailMessage.From and MailMessage.To properties to an address that exists on SmtpMail.SmtpServer. Some times this exception is thrown, when it really is a relay issue.

    Hope that helps,

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