Sending Email from an Application

Updated August 26, 2009
Iron Speed Designer V6.2 and later

The best way to send email from your application is by using Iron Speed Designer’s built-in send email action feature in the Properties dialog.  This requires no programming or custom code.

Programmatically sending an email

However, you can also programmatically send an email when a button is clicked in a generated application.  The easiest way to implement this is to override the Button_Click() method in the TableControl class.

Step 1:  Using the Application Wizard in Iron Speed Designer, create a set of application pages using a database table such as the Orders table in the Northwind database.

Step 2:  Use the Application Explorer to open the ShowOrdersTable.aspx page.

Step 3:  In Design Mode, select the Orders table panel and drag a Button control from the Toolbox onto the page next to the Export button.

Step 4:  Go to Tools, Properties....  Select the newly added button and set the following properties.

Tab

Property

Setting

Display

Button text

myButton

Bindings

Action

Custom

Bindings

Enable client-side validation

On (checked)

Step 5:  Override the Button_Click() method in the OrdersTableControl class, located in:

...\<Application Folder>\App_Code\Orders\ShowOrdersTable.Controls.cs or .vb

C#:

public override void Button_Click(object sender, EventArgs args)

{

     try

     {

          BaseClasses.Utils.MailSender email = new BaseClasses.Utils.MailSender();

          email.AddFrom("fromAddress@company.com");

          email.AddTo("toAddress@company.com");

          email.AddBCC("bccAddress@company.com");

          email.SetSubject("Confirmation");

          email.SetContent("Thank you for your request");

          email.SendMessage();

     }

     catch (System.Exception ex)

     {

          BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "UNIQUE_SCRIPTKEY", ex.Message);

     }

}

Visual Basic .NET:

Public Overrides Sub Button_Click(ByVal sender As Object, ByVal args As EventArgs)

     Try

          Dim email As BaseClasses.Utils.MailSender = New BaseClasses.Utils.MailSender

          email.AddFrom("fromAddress@company.com")

          email.AddTo("toAddress@company.com")

          email.AddBCC("bccAddress@company.com")

          email.SetSubject("Confirmation")

          email.SetContent("Thank you for your request")

          email.SendMessage()

     Catch ex As Exception

          BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "UNIQUE_SCRIPTKEY", ex.Message)

     End Try

End Sub

Step 6:  You may need to configure your email server authentication to accept emails sent from your application program.

See Also

Send Password by Email

Emailing the Contents of a Page

If You Have Problems Sending Email...