Home Search Member List Faq Register Login  
UltimateEmail
Re: Should my class work

Thread Starter: Jackxxx   Started: 03-31-2009 2:14 PM   Replies: 1
 Karamasoft Support Forums » General Discussions » UltimateEmail » Re: Should my class work
 Printable Version    « Previous Thread   Next Thread »
  31 Mar 2009, 2:14 PM
Jackxxx is not online. Last active: 4/14/2014 6:06:44 PM Jackxxx

Top 10 Posts
Joined on 10-15-2007
Posts 133
Should my class work

I have this class where I pass in a receipt_id and the stored procedure returns all the needed columns for the email and html for the message (letter). The stored procedure could return 1 or more rows. So far I can only get it to add invalid emails to the email log table. And the email address it trys to send to is always the first one from the first row.

Can you please offer some assitance with this?

Thank you very much.


Imports Microsoft.VisualBasicImports System.DataImports System.Data.SqlClientImports Karamasoft.WebControls.UltimateEmail

Public Class EmailOnEntry    Public Shared Sub SendEmail(ByVal intReceipt_ID As Int32)        ' Add event handler to merge mail and avoid sending email        Dim mailmerge As New MailMerge        AddHandler mailmerge.BeforeMerge, AddressOf OnBeforeMerge1        AddHandler mailmerge.BeforeSend, AddressOf OnBeforeSend1        AddHandler mailmerge.AfterSend, AddressOf OnAfterSend1        Dim ConnectStr As String = _        ConfigurationManager.ConnectionStrings("2ConnectionString").ConnectionString

        mailmerge.Host = System.Web.Configuration.WebConfigurationManager.AppSettings("MailServerHost")        mailmerge.Port = Integer.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings("MailServerPort"))        mailmerge.Username = System.Web.Configuration.WebConfigurationManager.AppSettings("MailServerUsername")        mailmerge.Password = System.Web.Configuration.WebConfigurationManager.AppSettings("MailServerPassword")

        mailmerge.IsBodyHtml = True        Dim Row As DataRow        Dim DS As New DataSet        Dim dt As DataTable        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 = "EmailOnEntrySproce"            AlertCommand.Parameters.AddWithValue("@Receipt_ID", intReceipt_ID)

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

            If dt.Rows.Count <> Nothing Then                Row = DS.Tables(0).Rows(0)                mailmerge.FromAddressTemplate = Row.Item("FromAddress").ToString()                mailmerge.ToAddressTemplate = Row.Item("Email").ToString()                mailmerge.SubjectTemplate = Row.Item("Subject").ToString()                mailmerge.BodyTemplate = HttpContext.Current.Server.HtmlDecode(Row.Item("Letter").ToString())                mailMerge.DataSource = DS

                mailmerge.SendMailMerge()            Else                'What should we do here?            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    Public Shared Sub OnBeforeMerge1(ByVal sender As Object, ByVal e As BeforeMergeEventArgs)        Dim dr As DataRow = e.DataRow        e.Body = HttpContext.Current.Server.HtmlDecode(dr("Letter"))        e.IsBodyHtml = True    End Sub    Public Shared Sub OnBeforeSend1(ByVal sender As Object, ByVal e As BeforeSendEventArgs)        Dim mergeStatus As Boolean = e.MergeStatus        Dim val As New Validator        Dim dr As Data.DataRow = e.DataRow

        Dim cmdInsert As SqlCommand        Dim myNewID As Integer        Dim ConnectStr As String = _        ConfigurationManager.ConnectionStrings("2ConnectionString").ConnectionString

        cmdInsert = New SqlCommand        cmdInsert.CommandText = "AddNewEmail"        cmdInsert.CommandType = CommandType.StoredProcedure        cmdInsert.Connection = New SqlConnection(ConnectStr)

        ' Validate email address using the Validator component before sending        If (val.ValidateEmailAddress(e.MergedMail.To(0).Address) <> ValidationLevel.Account) Then            ' Cancel this particular email by setting SendMergedMail to false            e.SendMergedMail = False

            cmdInsert.Parameters.AddWithValue("@Client_ID", e.DataRow.Item(0))            cmdInsert.Parameters.AddWithValue("@Order_ID", e.DataRow.Item(14))            cmdInsert.Parameters.AddWithValue("@EmailDateSent", System.DateTime.Today.ToShortDateString())            cmdInsert.Parameters.AddWithValue("@EmailTo", e.MergedMail.To.ToString)            cmdInsert.Parameters.AddWithValue("@EmailType", "ITY")            cmdInsert.Parameters.AddWithValue("@EmailStatus", "Invalid")            cmdInsert.Parameters.AddWithValue("@EmailSubject", e.MergedMail.Subject.ToString)            cmdInsert.Parameters.AddWithValue("@DateEntered", System.DateTime.UtcNow)            cmdInsert.Parameters.AddWithValue("@EnteredBy", HttpContext.Current.Profile.UserName)            cmdInsert.Parameters.AddWithValue("@LastUpdate", System.DateTime.UtcNow)            cmdInsert.Parameters.AddWithValue("@LastUpdateBy", HttpContext.Current.Profile.UserName)            cmdInsert.Parameters.AddWithValue("@EmailFrom", e.MergedMail.From.ToString)            If String.IsNullOrEmpty(e.DataRow.Item(15)) Then                cmdInsert.Parameters.AddWithValue("@EmailSelLetter", DBNull.Value)            Else                cmdInsert.Parameters.AddWithValue("@EmailSelLetter", e.DataRow.Item(15))            End If

            Try                cmdInsert.Connection.Open()                myNewID = cmdInsert.ExecuteScalar()            Catch ex As Exception                HttpContext.Current.Response.Write(ex.Message)            Finally                cmdInsert.Connection.Close()            End Try

        End If

    End Sub    Public Shared Sub OnAfterSend1(ByVal sender As Object, ByVal e As AfterSendEventArgs)        Dim sendStatus As Boolean = e.SendStatus

        Dim cmdInsert As SqlCommand        Dim myNewID As Integer        Dim ConnectStr As String = _        ConfigurationManager.ConnectionStrings("2ConnectionString").ConnectionString

        cmdInsert = New SqlCommand        cmdInsert.CommandText = "AddNewEmail"        cmdInsert.CommandType = CommandType.StoredProcedure        cmdInsert.Connection = New SqlConnection(ConnectStr)

        If (e.SendStatus) Then

            cmdInsert.Parameters.AddWithValue("@Client_ID", e.DataRow.Item(0))            cmdInsert.Parameters.AddWithValue("@Order_ID", e.DataRow.Item(14))            cmdInsert.Parameters.AddWithValue("@EmailDateSent", System.DateTime.Today.ToShortDateString())            cmdInsert.Parameters.AddWithValue("@EmailTo", e.MergedMail.To.ToString)            cmdInsert.Parameters.AddWithValue("@EmailType", "ITY")            cmdInsert.Parameters.AddWithValue("@EmailStatus", "Success")            cmdInsert.Parameters.AddWithValue("@EmailSubject", e.MergedMail.Subject.ToString)            cmdInsert.Parameters.AddWithValue("@DateEntered", System.DateTime.UtcNow)            cmdInsert.Parameters.AddWithValue("@EnteredBy", HttpContext.Current.Profile.UserName)            cmdInsert.Parameters.AddWithValue("@LastUpdate", System.DateTime.UtcNow)            cmdInsert.Parameters.AddWithValue("@LastUpdateBy", HttpContext.Current.Profile.UserName)            cmdInsert.Parameters.AddWithValue("@EmailFrom", e.MergedMail.From.ToString)            If String.IsNullOrEmpty(e.DataRow.Item(15)) Then                cmdInsert.Parameters.AddWithValue("@EmailSelLetter", DBNull.Value)            Else                cmdInsert.Parameters.AddWithValue("@EmailSelLetter", e.DataRow.Item(15))            End If            Try                cmdInsert.Connection.Open()                myNewID = cmdInsert.ExecuteScalar()            Catch ex As Exception                HttpContext.Current.Response.Write(ex.Message)            Finally                cmdInsert.Connection.Close()            End Try        Else            cmdInsert.Parameters.AddWithValue("@Client_ID", e.DataRow.Item(0))            cmdInsert.Parameters.AddWithValue("@Order_ID", e.DataRow.Item(14))            cmdInsert.Parameters.AddWithValue("@EmailDateSent", System.DateTime.Today.ToShortDateString())            cmdInsert.Parameters.AddWithValue("@EmailTo", e.MergedMail.To.ToString)            cmdInsert.Parameters.AddWithValue("@EmailType", "ITY")            cmdInsert.Parameters.AddWithValue("@EmailStatus", "Failed")            cmdInsert.Parameters.AddWithValue("@EmailSubject", e.MergedMail.Subject.ToString)            cmdInsert.Parameters.AddWithValue("@DateEntered", System.DateTime.UtcNow)            cmdInsert.Parameters.AddWithValue("@EnteredBy", HttpContext.Current.Profile.UserName)            cmdInsert.Parameters.AddWithValue("@LastUpdate", System.DateTime.UtcNow)            cmdInsert.Parameters.AddWithValue("@LastUpdateBy", HttpContext.Current.Profile.UserName)            cmdInsert.Parameters.AddWithValue("@EmailFrom", e.MergedMail.From.ToString)            If String.IsNullOrEmpty(e.DataRow.Item(15)) Then                cmdInsert.Parameters.AddWithValue("@EmailSelLetter", DBNull.Value)            Else                cmdInsert.Parameters.AddWithValue("@EmailSelLetter", e.DataRow.Item(15))            End If

            Try                cmdInsert.Connection.Open()                myNewID = cmdInsert.ExecuteScalar()            Catch ex As Exception                HttpContext.Current.Response.Write(ex.Message)            Finally                cmdInsert.Connection.Close()            End Try        End If    End SubEnd Class
 


  
  31 Mar 2009, 6:24 PM
Jackxxx is not online. Last active: 4/14/2014 6:06:44 PM Jackxxx

Top 10 Posts
Joined on 10-15-2007
Posts 133
Re: Should my class work
I got it working, Thanks anyway.
  
 Page 1 of 1 (2 items)
Karamasoft Support Forums » General Discussions » UltimateEmail » Re: Should my class work

You can add attachments
You can post new topics
You can reply to topics
You can delete your posts
You can edit your posts
You can create polls
You can vote in polls
Forum statistics are enabled
Forum is unmoderated

© 2002-2018 Karamasoft LLC. All rights reserved.