Imports Quartz Imports System.Net.Mail Imports System.Text.RegularExpressions ''' <summary> ''' material information automatic synchronization task '''</summary> <DisallowConcurrentExecution> Public Class Cls_DsxxtsMESJob Implements IJob Private JobName As String = "Scheduled message push" Private Shadows smtpClient As New SmtpClient() Public Sub Execute(context As IJobExecutionContext) Implements IJob. Execute Dim strSql As String = String. Empty Dim strBody As String = String. Empty Dim ttsql As String = String.Empty Dim wtsql As String = String.Empty try If m_csDBOp Is Nothing Then main.InitDB() End If g_csLog.Info("Scheduled message push") 'Determine whether there is data in the table strSql = $"SELECT * FROM dbo.T_TimedPush" Dim csDRResult = m_csDBOp.ADDGetDataTable(strSql) If csDRResult.Rows.Count > 0 Then For Each csDR As DataRow In csDRResult.Rows strBody = strBody & amp; "Type" & amp; csDR("F_TYPE").ToString & amp; vbCrLf strBody = strBody & amp; "Description" & amp; csDR("F_DESCRIBE").ToString & amp; vbCrLf strBody = strBody & amp; "query sql" & amp; csDR("F_SELECTSQL").ToString & amp; vbCrLf strBody = strBody & amp; "expression sql" & amp; csDR("F_DESQL").ToString & amp; vbCrLf strBody = strBody & amp; "Message Content" & amp; csDR("F_MESSAGE").ToString & amp; vbCrLf strBody = strBody & amp; "Mail" & amp; csDR("F_EMAIL").ToString & amp; vbCrLf strBody = strBody & amp; "Mail Address" & amp; csDR("F_EMAILADDRESS").ToString & amp; vbCrLf strBody = strBody & amp; "Watch" & amp; csDR("F_WATCH").ToString & amp; vbCrLf strBody = strBody & amp; "Watch Address" & amp; csDR("F_WATCHADDRESS").ToString Dim sql As String = csDR("F_SELECTSQL") 'Query whether there is data in this F_SELECTSQL that meets the conditions of sql Dim csSql = m_csDBOp.ADDGetDataTable(sql) If csSql.Rows.Count > 0 Then Dim filterExpression As String = csDR("F_DESQL").ToString() ' get filter expression Dim filterConditions() As String = Regex.Split(filterExpression, "[;|;]") ' Use semicolon or Chinese semicolon to separate filter conditions 'Use the Select method to get the rows that meet the conditions according to the filter conditions Dim filterRows() As DataRow = csSql. Select(String. Join(" AND ", filterConditions)) If filterRows. Length > 0 Then ttsql = $"Select * FROM dbo.T_TimedPush where F_EMAIL='True'" 'Judge whether F_EMAIL is the checkbox is selected Dim csFSql = m_csDBOp.ADDGetDataTable(ttsql) If csFSql.Rows.Count > 0 Then Dim mailSubject As String = csDR("F_TYPE") ' mail subject Dim mailBody As String = strBody ' mail content Dim mailAddresses As String() = Regex.Split(csDR("F_EMAILADDRESS").ToString, "[;|;]") 'csDR("F_EMAILADDRESS").Split(";" ) ' accept address Dim mailAddress As New MailAddressCollection() For Each address In mailAddresses mailAddress. Add(address) Next SendMail(mailAddress, mailBody, mailSubject) End If End If If WatchRows. Length > 0 Then try Dim strTemp As String = String. Empty If m_intCount = 6553 Then m_intCount = 0 End If m_intCount = m_intCount + 1 ' Use regular expression to split string from csDR("F_WATCHADDRESS") field and get array of device numbers Dim strSN As String() = Regex.Split(csDR("F_WATCHADDRESS").ToString, "[;|;]") Dim strMSG As String = csDR("F_MESSAGE") Dim csWaitHandle As New ManualResetEvent(False) ' Construct the message string to be sent, splicing the device number and message content into a complete message strTemp = $"SGN=5 + {String.Join(" + ", strSN)};SCM={strMSG};EV={m_intCount};" Dim intCount As Integer = 0 Dim bytes() As Byte = System.Text.ASCIIEncoding.Default.GetBytes(strTemp) ' Send a message SendMsg(bytes, m_strUDPServer, 5000) m_intCount = m_intCount + 1 Catch ex As Exception UpdateUI(ex.Message) End Try End If End If Next End If Catch ex As Exception g_csLog.Error(ex.Message & amp; vbCrLf & amp; ex.StackTrace) End Try End Sub ' encapsulates the method used to send mail ''' <param name="mailAddress">Sender</param> ''' <param name="mailBody">Mail content</param> ''' <param name="mailSubject">Mail subject</param> Public Shared Sub SendMail(ByVal mailAddress As MailAddressCollection, ByVal mailBody As String, ByVal mailSubject As String) ' Initialize the SmtpClient object SmtpClient.Host = "smtp.163.com" ' Set the port number and credentials of the SMTP server smtpClient.Port = 25 'Set the port number according to the actual situation smtpClient.EnableSsl = False smtpClient.Credentials = New Net.NetworkCredential("@163.com", "Authorization Code") 'Fill in the account name and password according to the actual situation 'Create a MailMessage object and set various attributes (sender, recipient, email subject, email content) Dim mailMessage As New MailMessage() 'Dim message = ("@163.com").Split(New Char() {";"c}) ' mailMessage.To.Add(message.ToString) For Each adress In mailAddress mailMessage.To.Add(adress) Next mailMessage.Subject = mailSubject mailMessage.Body = mailBody mailMessage.From = New MailAddress("@163.com") mailMessage.IsBodyHtml = True ' send email try smtpClient. Send(mailMessage) g_csLog.Info("sent successfully") Catch ex As Exception g_csLog.Error("Failed to send" & amp; ex.Message) End Try End Sub End Class
The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge Network skill treeHome pageOverview 33579 people are studying systematically