Sending mail through managed code - InfoPath Dev
in

InfoPath Dev

Having trouble finding a blog or post that answers your question? Check out our Custom Search Page

Sending mail through managed code

Last post 09-29-2012 04:37 AM by MADOURI. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 08-03-2006 09:58 PM

    Sending mail through managed code

    Hi Friends,

    In my application i need to send email notification when the form is submitted. here i wrote code in the button click event. my problem is it is working when i tested in the server, but when the form is submitted in the client mechine means after publishint to sharepoint library it is promting with the error message.

    here is my code
    MailMessage mailMsg=new MailMessage();
    thisXDocument.UI.Alert("Hi");
    mailMsg.From = "spssrv2@lgcnsglobal.com";
    //thisXDocument.UI.Alert(strReportingToMailId.text);
    mailMsg.To = mail.text; //strReportingToMailId.text;
    //mailMsg.Cc =strInitiatedUserMailId.text;
    mailMsg.Subject = "sending the mail when the button is clicked";
    mailMsg.BodyFormat = MailFormat.Html;
    //mailMsg.Body = nv.Body ;
    SmtpMail.Send( mailMsg );

    thisApplication.ActiveWindow.Close(true);

    the error message i am getting is

    Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
    at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
    at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed)
    at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
    at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
    at SendMail.SendMail.Button_OnClick(DocActionEvent e)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

    Could any one please solve my problem?
    thanks in advance...
  • 08-03-2006 11:22 PM In reply to

    Re: Sending mail through managed code

    Hi Krishna Prasad,
    This is the code I use to send mail.And it works fine.
    I dont use Microsoft Outlook.I use lotus notes.

    MailMessage msgmail = new MailMessage();
    msgmail.Body = "You have a new form awaiting your Approval";
    msgmail.From = "abcd@XYZ.com";
    msgmail.To = "abhishek.keshav@lntinfotech.com";
    msgmail.Subject = "Alert";
    SmtpMail.SmtpServer = "<Default SMTP Virtual Server Domain Name>" ;//U r missing this line
    SmtpMail.Send(msgmail);

    In ur system's IIS,u can find a Default SMTP Virtual server.Under that u have "Domains".Clicking that reveals ur domain name.

    Regards,
    Abhishek
  • 08-04-2006 12:51 AM In reply to

    Re: Sending mail through managed code

    Hello

    Read the link below
    http://www.sharepointblogs.com/ssa/archive/2006/06/02/8029.aspx

    Hope it helps you
    Kalyan G Reddy
    Infopath MVP 2007 and 2008
  • 08-20-2008 03:31 PM In reply to

    Re: Sending mail through managed code

    Abhishek

    I am a real novice a coding, so can you assist me with this.

    I  have added a Button to my form, selected Rules and Custom Code which have opened Visual Studio and I have added your code (as per example)

    Public Sub CTRL48_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ' Write your code here.

    MailMessage msgmail = new MailMessage();

    msgmail.Body = "You have a new form awaiting your Approval";

    msgmail.From = "michael.campbell@carnivalaustralia.com";

    msgmail.To = "lidia.cardillo@carnivalaustralia.com";

    msgmail.Subject = "Alert";SmtpMail.SmtpServer = "999999.carnivalaustralia.com" ;//U r missing this line

    SmtpMail.Send(msgmail);

    End Sub

    End Class

    I get the following errors.

    Name 'MailMessage' is not declaried

    Type 'MailMessage' is not defined

     

  • 08-20-2008 04:14 PM In reply to

    Re: Sending mail through managed code

    The code sample is in C#. It looks as if your form is set to use VB. VB declares variables differently (among other things, such as no end of line semicolon). You can either remove the code in your form and set the programming language to C# and try this sample again, or you can try to convert the sample to VB. At first glance, you should just be able to remove all semicolons, mark anything that starts with "//" with a single quote instead (different comment markers) and change this:

    MailMessage msgmail = new MailMessage();

    to this:

    Dim msgmail As New MailMessage()

    You'll probably need to add an import statement as well like this:

    Imports System.Net.Mail

    at the top of your code.

    Hilary Stoupa
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 08-20-2008 05:26 PM In reply to

    Re: Sending mail through managed code

    Hilary

    You are dealing with a real novie here....so I need some more assistance.

    I changed from VB to C# and added the code, as follows:

    MailMessage msgmail = new MailMessage();

    msgmail.Body = "You have a new form awaiting your Approval";

    msgmail.From = "michael.campbell@carnivalaustralia.com";

    msgmail.To = "lidia.cardillo@carnivalaustralia.com";

    msgmail.Subject = "Alert";

    SmtpMail.SmtpServer = "999999.carnivalaustralia.com";//U r missing this line

    SmtpMail.Send(msgmail);

    But when I debug, I get the following errors:

    "The type or namesopace name 'MailMessage' could not be found (are you missing a using directive or an assembly reference'

    "The name 'SmtpMail' does not exisst in the current context'

  • 08-20-2008 06:29 PM In reply to

    Re: Sending mail through managed code

    Okay -- try this. Add at the top of your code windows (under the other "using" statements):

    using System.Net.Mail;

    Now, instead of the above code, try this:

    MailAddress from = new MailAddress("michael.campbell@carnivalaustralia.com");
    MailAddress to = new MailAddress("lidia.cardillo@carnivalaustralia.com");
    MailMessage msgmail = new MailMessage(from,to);
    msgmail.Body = "You have a new form awaiting your Approval";
    msgmail.Subject =
    "Alert";
    SmtpClient client = new SmtpClient("999999.carnivalaustralia.com");
    client.Send(msgmail);

    Obviously, you need to change the to and from addresses, as well as the SmtpClient server address. The code compiles -- I haven't tried actually running it, so let me know if you have trouble.

    Hilary Stoupa
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 08-21-2008 03:15 PM In reply to

    Re: Sending mail through managed code

    Hilary

    Thank you so much....it's all fine now.

    Regards

     

    Michael

  • 08-24-2008 03:36 PM In reply to

    Re: Sending mail through managed code

    Hi

    I used your email to code, as we use Lotus Notes and not Outlook. When I submit the InfoPath form, I get the following error message:

    System.Security.SecurityException
    Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.CodeAccessPermission.Demand()
       at System.Net.Mail.SmtpClient.Initialize()
       at System.Net.Mail.SmtpClient..ctor(String host)
       at SAMPLE___Email_via_Lotus_Notes.FormCode.LNEmail_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

     Any suggestions on what may be causing this?

    Thanks

    Michael

  • 08-24-2008 05:20 PM In reply to

    Re: Sending mail through managed code

    Yes -- your form will need to be full trust. Try setting to full trust and see what happens.... Sadly, full trust forms have their own set of challenges, see this article for more information.

    Hilary Stoupa
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 11-19-2008 04:20 PM In reply to

    Re: Sending mail through managed code

    Hello Hilary!  It would appear as if you have your signature on every new skill that I try to learn here!  You are very busy!

    At any rate, is it possible to manipulate just the 'from' on an email?  I have a rule to submit to database/sharepoint/email and it works swimmingly, but I would like to hard code the 'from' information.  We have consolidated our customer care department into regional offices so we have a call center that answers calls for many cities.  The workflow is handled through IP (many thanks to you) and ultimately an email is generated to a trade partner requesting that warranty work be performed.  We have set up email accounts by division (-divisionname-customercare@mycompany.com) as well as a call center account (customercare@mycompany.com).  The folks working the call center have access to these accounts and they monitor all the emails with that regard.  The problem is that a particular individual will initiate the email, the trade partner will respond and instead of it coming to the community inbox, it goes back to that individual.  We need it to go back to the community inbox.  If I am unable to accomplish just hard coding the 'from' and I have to build the entire email sender, I will also need to be able to embed the current view as HTML in the email.

    I never have the easy ones, do I? 

    Fishman
  • 11-19-2008 05:18 PM In reply to

    Re: Sending mail through managed code

    Nope, you never have the easy ones! From what I know and read in the documentation on MSDN, you will not be able to set just the 'from' for an Email Submit connection. If you check this link, you'll see that 'from' isn't in the listed members of the email connection class.

    Browsing some other posts on this forum, someone mentions that script in the IP2003 Issue Tracking sample form copies the form into the body, but the post that had that suggested they were just creating a text view, so not necessarily an exact replica...

    Also, this link was mentioned in an earlier post today as a way to set the 'from' field, you may want to check it out.

    Wish I had better news!

    Hilary Stoupa
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 10-27-2009 01:46 PM In reply to

    • dggill
    • Not Ranked
    • Joined on 10-27-2009
    • Posts 1

    Re: Sending mail through managed code

    I have been trying to use the code written in the earlier part of this thread.  Following is my code which yields the error message below as well.

    function XDocument::OnSubmitRequest(eventObj)
    {
     If the submit operation is successful, set eventObj.ReturnStatus = true;
     MailMessage msgmail = new MailMessage();
     msgmail.Body = "You have a new Best Practice form awaiting your Approval";
     msgmail.From = "xyz@xyz.com";
     msgmail.To = "xyz.abc@xyz.com";
     msgmail.Subject = "Best Practice Alert";
     SmtpMail.SmtpServer = "xyzr.xyz.com";
     SmtpMail.Send(msgmail);

    I get the following message:

    expected ';'

    File: Script.js

    Line:25

    MailMessage msgmail = new MailMessage( );

    I am not a programer but nothing seems to work.

     

    Filed under: , ,
  • 09-29-2012 04:37 AM In reply to

    Re: Sending mail through managed code

    hi,

    is there any way to send an email notification 4 months after that the form is submitted....?

    cdt. 

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