View Full Version : [Trinity Core] Sending Mail

08-08-2013, 05:25 AM
Wrote this for someone on ******* 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.

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)

MaxID = CDbl(command.ExecuteScalar())

MaxID = MaxID + 1

End Using
End Using
End Sub

Public Shared Sub SendMail()
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_ti me,@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
Catch ex As Exception
End Try
End Using
End Sub

08-08-2013, 05:35 AM
Very sweet! Greatly appreciated. :D

08-08-2013, 05:40 AM
No problem and sorry for the wrong section!

08-08-2013, 05:42 AM
No problem and sorry for the wrong section!

No problem. :D