1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Email form submissions

Email form submissions

9 posts, 0 answered
  1. Steve
    Steve avatar
    6 posts
    Registered:
    13 Aug 2012
    13 Aug 2007
    Link to this post
    We are developing our first site with sitefinity and need to create numerous forms to submit information by email (using our own smtp server).  Can someone recommend a control or method that works with sitefinity and is easy to create and maintain?  Thanks

    Steve Ledbetter
    RFMS, Inc
  2. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    13 Aug 2007
    Link to this post

    We use Telerik's RadAjaxManager to send form data to a web service. This is done to improve the performance of the form as the web service is asynchronous. An intra site module to allow us access to review the information and export it to excel after it has been emailed to both the person who submitted the form and a company representative. The configuration looks like this:

    <AlightenContactConfiguration serverAddress="mail.alighten.com" serverPort="25" serverSpecifyPort="false" serverAuthenticate="true" clientTemplate="~/Files/templates/contactClientTemplate.html" employeeTemplate="~/Files/templates/contactEmployeeTemplate.html" baseURL="" from="Ben&lt;info@alighten.com&gt;" employeeRecipients="Ben&lt;email@yahoo.com&gt;;Ben&lt;info@alighten.com&gt;" username="test@alighten.com" password="test" clientSubject="Alighten | Request received {0} {1}" employeeSubject="PatioSource | New request from {0} {1}"/> 


     Above the section group name=Telerik add:

    <section name="AlightenContactConfiguration" type="AlightenContactConfiguration"></section> 

    In the app_code folder place the configuration class:

    Public Class AlightenContactConfiguration  
        Inherits ConfigurationSection  
     
        <ConfigurationProperty("serverAddress", _  
                        IsRequired:=True, IsKey:=True)> _  
          Public Property ServerAddress() As String 
            Get 
                Return CStr(Me("serverAddress"))  
            End Get 
            Set(ByVal value As String)  
                Me("serverAddress") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("serverPort", _  
                        IsRequired:=True, IsKey:=True)> _  
          Public Property ServerPort() As String 
            Get 
                Return CStr(Me("serverPort"))  
            End Get 
            Set(ByVal value As String)  
                Me("serverPort") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("serverSpecifyPort", _  
                        IsRequired:=True, IsKey:=True)> _  
          Public Property ServerSpecifyPort() As String 
            Get 
                Return CStr(Me("serverSpecifyPort"))  
            End Get 
            Set(ByVal value As String)  
                Me("serverSpecifyPort") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("serverAuthenticate", _  
                        IsRequired:=True, IsKey:=True)> _  
          Public Property ServerAuthenticate() As String 
            Get 
                Return CStr(Me("serverAuthenticate"))  
            End Get 
            Set(ByVal value As String)  
                Me("serverAuthenticate") = value  
            End Set 
        End Property 
     
     
        <ConfigurationProperty("clientTemplate", _  
                        IsRequired:=True)> _  
          Public Property ClientTemplate() As String 
            Get 
                Return CStr(Me("clientTemplate"))  
            End Get 
            Set(ByVal value As String)  
                Me("clientTemplate") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("employeeTemplate", _  
                       IsRequired:=True)> _  
         Public Property EmployeeTemplate() As String 
            Get 
                Return CStr(Me("employeeTemplate"))  
            End Get 
            Set(ByVal value As String)  
                Me("employeeTemplate") = value  
            End Set 
        End Property 
     
     
        <ConfigurationProperty("baseURL", _  
                        IsRequired:=True)> _  
          Public Property BaseURL() As String 
            Get 
                Return CStr(Me("baseURL"))  
            End Get 
            Set(ByVal value As String)  
                Me("baseURL") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("from", _  
                           IsRequired:=True)> _  
             Public Property From() As String 
            Get 
                Return CStr(Me("from"))  
            End Get 
            Set(ByVal value As String)  
                Me("from") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("username", _  
                         IsRequired:=True)> _  
           Public Property Username() As String 
            Get 
                Return CStr(Me("username"))  
            End Get 
            Set(ByVal value As String)  
                Me("username") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("password", _  
                          IsRequired:=True)> _  
            Public Property Password() As String 
            Get 
                Return CStr(Me("password"))  
            End Get 
            Set(ByVal value As String)  
                Me("password") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("employeeRecipients", _  
                         IsRequired:=True)> _  
           Public Property EmployeeRecipients() As String 
            Get 
                Return CStr(Me("employeeRecipients"))  
            End Get 
            Set(ByVal value As String)  
                Me("employeeRecipients") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("clientSubject", _  
                           IsRequired:=True)> _  
             Public Property ClientSubject() As String 
            Get 
                Return CStr(Me("clientSubject"))  
            End Get 
            Set(ByVal value As String)  
                Me("clientSubject") = value  
            End Set 
        End Property 
     
        <ConfigurationProperty("employeeSubject", _  
                           IsRequired:=True)> _  
             Public Property EmployeeSubject() As String 
            Get 
                Return CStr(Me("employeeSubject"))  
            End Get 
            Set(ByVal value As String)  
                Me("employeeSubject") = value  
            End Set 
        End Property 
     
     
    End Class 
     


    And finally the code to put the data in the database and send the email.

    Imports System.Web.Services  
    Imports System.Web.Services.Protocols  
     
    Imports System  
    Imports System.Data  
    Imports System.Configuration  
    Imports System.Collections  
    Imports System.Web  
    Imports System.Web.Security  
    Imports System.Web.UI  
    Imports System.Web.UI.WebControls  
    Imports System.Web.UI.WebControls.WebParts  
    Imports System.Web.UI.HtmlControls  
    Imports System.Reflection  
     
    Imports Telerik  
    Imports Telerik.Cms  
    Imports Telerik.DataAccess  
    Imports Telerik.WebControls  
    Imports Nolics.ORMapper.Base  
     
    Imports Alighten.Modules.Data.Alighten.Contacts  
    Imports System.Net.Mail  
    Imports System.IO  
     
     
    <WebService(Namespace:="http://tempuri.org/")> _  
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _  
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _  
    Public Class contactService  
        Inherits System.Web.Services.WebService  
     
        <System.Web.Services.WebMethod()> _  
      Public Function submitForm(ByVal name As StringByVal company As StringByVal email As StringByVal newsletter As BooleanByVal category As StringByVal message As StringAs String 
            Try 
                Dim bCreateData As Boolean = False 
                Dim bSendClientMail As Boolean = False 
                Dim bSendEmployeeMail As Boolean = False 
                Dim bResponse As Boolean = False 
     
                bCreateData = CreateData(name, company, email, newsletter, category, message)  
                bSendClientMail = SendClientMail(name, company, email, newsletter, category, message)  
                bSendEmployeeMail = SendEmployeeMail(name, company, email, newsletter, category, message)  
     
     
                If bCreateData And bSendClientMail And bSendEmployeeMail Then 
                    bResponse = True 
                End If 
     
                Return bResponse  
            Catch ex As Exception  
                Return ex.Message  
            End Try 
        End Function 
     
        Private Shared Initialized As Boolean 
     
        Private Shared Sub Initialize()  
            If Not Initialized Then 
                Dim alightenAssembly As Assembly 
                alightenAssembly = GetType(Contact).Assembly 
                DataConnection.Initialize(False, alightenAssembly)  
                Dim provider As OdbDataProvider  
                provider = NolicsHelper.SetConnection("DefaultConnection")  
                provider.Upgrade()  
                Initialized = True 
            End If 
        End Sub 
        Private Function CreateData(ByVal name As StringByVal company As StringByVal email As StringByVal newsletter As BooleanByVal category As StringByVal message As StringAs Boolean 
            Try 
                Initialize()  
     
                Dim transaction As New Transaction  
                Dim item As New Contact  
     
                OdbClass.Create(item, transaction)  
     
                item.Name = name  
                item.Company = company  
                item.Email = email  
                item.newsletter = newsletter  
                item.Category = category  
                item.Message = message  
     
                transaction.Commit()  
            Catch ex As Exception  
     
            End Try 
        End Function 
     
     
        Private Function SendClientMail(ByVal name As StringByVal company As StringByVal email As StringByVal newsletter As BooleanByVal category As StringByVal message As StringAs Boolean 
     
            Dim config As New AlightenContactConfiguration  
            config = CType(System.Configuration.ConfigurationManager.GetSection("AlightenContactConfiguration"), AlightenContactConfiguration)  
     
            Dim objMail As New MailMessage()  
     
            Dim urlResolver As New System.Web.UI.Control  
            Dim filePath As String 
            Dim body As String = String.Empty  
            Dim subject As String = String.Empty  
            Dim oRead As StreamReader  
     
            Try 
                filePath = Server.MapPath(config.ClientTemplate)  
                oRead = System.IO.File.OpenText(filePath)  
                body = oRead.ReadToEnd()  
     
                body = String.Format(body, name, company, email, newsletter.ToString, category, message)  
                subject = String.Format(config.ClientSubject, name, company, email, newsletter.ToString, category, message)  
     
                objMail.From = New MailAddress(config.From)  
     
                objMail.To.Add(New MailAddress(email))  
                objMail.IsBodyHtml = True 
                objMail.Subject = subject  
                objMail.Body = body  
     
                Dim mailClient As New System.Net.Mail.SmtpClient()  
     
                If config.ServerAuthenticate.ToUpper = "true".ToUpper Then 
                    Dim basicAuthenticationInfo As New System.Net.NetworkCredential(config.Username, config.Password)  
                    mailClient.UseDefaultCredentials = False 
                    mailClient.Credentials = basicAuthenticationInfo  
                End If 
     
                If config.ServerSpecifyPort.ToUpper = "true".ToUpper Then 
                    mailClient.Port = CInt(config.ServerPort)  
                End If 
     
                mailClient.Host = config.ServerAddress  
     
                mailClient.Send(objMail)  
     
                Return True 
     
            Catch ex As Exception  
                Return False 
            End Try 
        End Function 
        Private Function SendEmployeeMail(ByVal name As StringByVal company As StringByVal email As StringByVal newsletter As BooleanByVal category As StringByVal message As StringAs Boolean 
     
            Dim config As New AlightenContactConfiguration  
            config = CType(System.Configuration.ConfigurationManager.GetSection("AlightenContactConfiguration"), AlightenContactConfiguration)  
     
            Dim objMail As New MailMessage()  
     
            Dim urlResolver As New System.Web.UI.Control  
            Dim filePath As String 
            Dim body As String = String.Empty  
            Dim subject As String = String.Empty  
            Dim sAddr As String 
            Dim sAddrs As String()  
            Dim oRead As StreamReader  
     
            Try 
                filePath = Server.MapPath(config.EmployeeTemplate)  
                oRead = System.IO.File.OpenText(filePath)  
                body = oRead.ReadToEnd()  
     
                body = String.Format(body, name, company, email, newsletter.ToString, category, message)  
                subject = String.Format(config.EmployeeSubject, name, company, email, newsletter.ToString, category, message)  
     
                objMail.From = New MailAddress(config.From)  
     
                sAddr = config.EmployeeRecipients  
                sAddrs = Split(sAddr, ";")  
     
                For Each sAddr In sAddrs  
                    objMail.To.Add(New MailAddress(Trim(sAddr)))  
                Next 
     
     
                objMail.IsBodyHtml = True 
                objMail.Subject = subject  
                objMail.Body = body  
     
                Dim mailClient As New System.Net.Mail.SmtpClient()  
     
                If config.ServerAuthenticate.ToUpper = "true".ToUpper Then 
                    Dim basicAuthenticationInfo As New System.Net.NetworkCredential(config.Username, config.Password)  
                    mailClient.UseDefaultCredentials = False 
                    mailClient.Credentials = basicAuthenticationInfo  
                End If 
     
                If config.ServerSpecifyPort.ToUpper = "true".ToUpper Then 
                    mailClient.Port = CInt(config.ServerPort)  
                End If 
     
                mailClient.Host = config.ServerAddress  
     
                mailClient.Send(objMail)  
     
                Return True 
     
            Catch ex As Exception  
     
            End Try 
        End Function 
     
     
     
        Private Function FixupUrl(ByVal url As StringAs String 
            Try 
                If url.StartsWith("~"Then 
                    Return (HttpContext.Current.Request.ApplicationPath + url.Substring(1)).Replace("//""/")  
                End If 
     
                Return url  
            Catch ex As Exception  
                Return Nothing 
            End Try 
        End Function 
     
    End Class 
     


    If you would like to see the simple intra site module I can send you that as well. Its pretty basic. Just a grid and a form view for editing the grid. It is very similar to the Jobs module that comes with Sitefinity. But if you just want to use the email functionality this should get you there. Also, there is a setting in the system.net.mail that allows you to send email asynchronously. Therefore if you don't want to put the data in the database you can just copy the email function and paste it in your form usercontrol code behind.
  3. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    15 Aug 2007
    Link to this post
    Hi Ben,

    Thank you for sharing your knowledge and giving extensive explanation to Steve's question. Your points have been updated.

     

    Kind regards,
    Sonya
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    25 Aug 2007
    Link to this post
    Update: SendAsync does not work in Sitefinity. You will get a threading out of context error because the page needs to be set to allowasync=true. This is not currently available in Sitefinity. It's not really a big deal though as it's pretty fast anyway. Just don't add the upgrade database line when initializing the Nolics connection.

    Sincerely,

    Ben
  5. Courtney
    Courtney avatar
    9 posts
    Registered:
    30 Mar 2005
    13 Sep 2007
    Link to this post
    Hey Ben,

    Do you think you can post or email me the intrasite module? I'm curious as to how you got the rest set up.
  6. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    13 Sep 2007
    Link to this post
    Sure thing.

    We have recreated the form without the web service to simplify deployment of the module. I will email the module, usercontrols, and instructions this evening.

    Sincerely,

    Ben
  7. Courtney
    Courtney avatar
    9 posts
    Registered:
    30 Mar 2005
    13 Sep 2007
    Link to this post
    Thanks - that would be much appreciated.

    Sincerely,

    Richie
  8. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    14 Sep 2007
    Link to this post
    I posted the Intrasite contact module files and some instructions at:

    http://www.alighten.com/Files/blogs/bnye/downloads/Intrasite%20Contct%20Module.zip

    Please let me know if you have any questions.

    Sincerely,

    Ben
  9. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    14 Sep 2007
    Link to this post
    Update: I added the Contact.dbclass nolics file to the zip. You will need to create a Nolics project with a similar dbclass and build to add your nolics dll to your solution.
Register for webinar
9 posts, 0 answered