• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[Trinity Core] Sending Mail

Archenemy

Enthusiast
Wrote this for someone on ac-web and for a ticket reader I'm making for myself. Thought I'd share so maybe it would help someone else out. Just set the value of each string except for expire time and deliver time. That's taken care of by taking the datetime and converting it to a unix timestamp. Also gets the max id in the mail table since it does not auto inc and adds one to the max and then inserts the data.

Code:
 Public Shared Mail_id As String
        Public Shared Mail_messageType As String
        Public Shared Mail_stationery As String
        Public Shared Mail_mailTemplateId As String
        Public Shared Mail_sender As String
        Public Shared Mail_receiver As String
        Public Shared Mail_subject As String
        Public Shared Mail_body As String
        Public Shared Mail_has_items As String
        Public Shared Unix_TimeStamp As Integer = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds
        Public Shared Mail_expire_time As String = Unix_TimeStamp + 2592000
        Public Shared Mail_deliver_time As String = Unix_TimeStamp
        Public Shared Mail_money As String
        Public Shared Mail_cod As String
        Public Shared Mail_checked As String
        Public Shared ConnectionString As String
        Public Shared MaxID As String
        Public Shared Connection As New MySqlConnection


        Public Shared Sub GetMaxID()
            Using connection As New MySqlConnection(ConnectionString)
                Using command As New MySqlCommand("SELECT MAX(id) FROM mail", connection)
                    connection.Open()

                    MaxID = CDbl(command.ExecuteScalar())

                    MaxID = MaxID + 1

                    connection.Close()
                    connection.Dispose()
                End Using
            End Using
        End Sub


        Public Shared Sub SendMail()
            GetMaxID()
            Connection.ConnectionString = ConnectionString
            Dim Query As String = "INSERT INTO Mail (`id`, `messageType`, `stationery`, `mailTemplateId`, `sender`, `receiver`, `subject`, `body`, `has_items`, `expire_time`, `deliver_time`, `money`, `cod`, `checked`) values (@Mail_id,@Mail_messageType,@Mail_stationery,@Mail_mailTemplateId,@Mail_sender,@Mail_receiver,@Mail_subject,@Mail_body,@Mail_has_items,@Mail_expire_time,@Mail_deliver_time,@Mail_money,@Mail_cod,@Mail_checked)"
            Using SqlCommand As New MySqlCommand()
                With SqlCommand
                    .CommandText = Query
                    .Connection = Connection
                    .CommandType = CommandType.Text
                    .Parameters.AddWithValue("@Mail_id", MaxID)
                    .Parameters.AddWithValue("@Mail_messageType", Mail_messageType)
                    .Parameters.AddWithValue("@Mail_stationery", Mail_stationery)
                    .Parameters.AddWithValue("@Mail_mailTemplateId", Mail_mailTemplateId)
                    .Parameters.AddWithValue("@Mail_sender", Mail_sender)
                    .Parameters.AddWithValue("@Mail_receiver", Mail_receiver)
                    .Parameters.AddWithValue("@Mail_subject", Mail_subject)
                    .Parameters.AddWithValue("@Mail_body", Mail_body)
                    .Parameters.AddWithValue("@Mail_has_items", Mail_has_items)
                    .Parameters.AddWithValue("@Mail_expire_time", Mail_expire_time)
                    .Parameters.AddWithValue("@Mail_deliver_time", Mail_deliver_time)
                    .Parameters.AddWithValue("@Mail_money", Mail_money)
                    .Parameters.AddWithValue("@Mail_cod", Mail_cod)
                    .Parameters.AddWithValue("@Mail_checked", Mail_checked)
                End With
                Try
                    Connection.Open()
                    SqlCommand.ExecuteNonQuery()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End Using
        End Sub
 
Top