UltimateEmail
Topic: Emails take a long time
Karamasoft Support Forums

Page 1 of 1 (1 items)


Posted by Jackzzz on 11-09-2012 5:57 PM

I have this code in a vb class named systemalerts. The code works fine, but the emails take about 8 to 10 seconds to go out. The sproc executes in less than a second if I hard code an ID in it, so I was thinking there might be a setting for the UltimateEmail that could help with the speed or maybe you might have a suggestion for the code to speed it up.

Thank you,

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports Karamasoft.WebControls.UltimateEmail

Public Class SystemAlerts

    Public Shared Sub SendAlert(ByVal intDon_ID As Int32)
        Dim mailMerge As New MailMerge
        mailMerge.IsBodyHtml = True
        Dim Row As DataRow
        Dim DS As New DataSet
        Dim dt As DataTable
        Dim ConnectStr As String = _
        ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim AlertCommand As New SqlCommand
        Dim MyAdapter As New SqlDataAdapter(AlertCommand)

        Try

            'Get Alert Email Columns
            AlertCommand.CommandType = CommandType.StoredProcedure
            AlertCommand.Connection = New SqlConnection(ConnectStr)
            AlertCommand.CommandText = "Alert"

            AlertCommand.Parameters.AddWithValue("@Don_ID", intDon_ID)

            MyAdapter.Fill(DS)
            dt = DS.Tables(0)

            If dt.Rows.Count <> Nothing Then
                Row = DS.Tables(0).Rows(0)
                mailMerge.FromDisplayNameTemplate = Row.Item("FromName").ToString()
                mailMerge.FromAddressTemplate = Row.Item("FromAddress").ToString()
                mailMerge.ToAddressTemplate = Row.Item("AlertTo").ToString()
                mailMerge.SubjectTemplate = Row.Item("AlertSubject").ToString()
                mailMerge.BodyTemplate = HttpContext.Current.Server.HtmlDecode(Row.Item("AlertMessage").ToString())
                mailMerge.DataSource = DS

                'Don't Send if False
                If Row.Item("ActivateAlert") = True Then
                    mailMerge.SendMailMerge()
                End If
            End If
        Catch EX As Exception
            HttpContext.Current.Response.Write(EX.Message)
        Finally
            MyAdapter.Dispose()
            AlertCommand.Dispose()
            AlertCommand.Connection.Close()
            DS.Dispose()
        End Try
    End Sub
End Class

I call it like this in my code behind

SystemAlerts.SendAlert(iDonID)