A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Saturday, September 3, 2005

Sending email in InfoPath using third party component

You can send email in InfoPath using third party components. You must use InfoPath Toolkit. Toolkit is required to write managed code in InfoPath. To see how you can send email using System.Web.Mail namespace, read following post:

Sending Email From InfoPath Using Managed Code

I used ASPEmail component in my code, this component can be downloaded from the following link:


After downloading the component, install it on your machine. Create an InfoPath form and add a button to it. Double click the button and select "Edit Form Code..." from the dialog box. This will open code editor (in Visual Studio). Add component in references. Right click "References" in solution explorer and add a reference to ASPEmail component (ASPEmailLib.dll).
Include namespace in your code: using ASPEMAILLIB;
Add following code click event of the button:

[InfoPathEventHandler(MatchPath="CTRL1_1", EventType=InfoPathEventType.OnClick)]
public void CTRL1_1_OnClick(DocActionEvent e)
ASPEMAILLib.IMailSender objMail;
objMail = new ASPEMAILLib.MailSender();
objMail.Host = "smtp.yourdomain.com";
objMail.From = "share.point@yourdomain.com";
objMail.AddAddress("user@sharepoint.com" , "John Doe");
objMail.Body = "This a test mail and currently logged in user is " + System.Environment.UserName;

You can send attachments as well. Add following line before the "send" statement:
objMail.AddAttachment(your file path);
To add CC address, use the following line:
objMail.AddCC("email address","user name");
To add BCC address, use the following line:
objMail.AddBcc("email address","user name");
To send HTML mail, set isHTML property to true:
objMail.IsHTML = true;
To send mail to a newsgroup:
objMail.SendToNewsgroup(string newsgroup);


No comments:

Post a Comment