我有一个模块,它像这样从 vb.net 控制台应用程序调用存储过程。这个存储过程中有很多打印语句。当我执行此控制台应用程序时,它将在控制台中显示消息。我想获取这些消息并通过邮件发送
Dim Con As New SqlConnection(connectionString)
Dim cmd As New SqlCommand("SaveReceiptsFromFile_GFF", Con)
Try
Using Con
Con.Open()
cmd.ExecuteNonQuery()
End Using
Catch ex As SqlException
Console.WriteLine(ex.Message)
sendmailwhenfail()
End Try
Con.Close()
我发送邮件的模块是这样的:
Public Shared Sub sendmailwhenfail()
Try
Dim AnEmailMessage As New MailMessage
AnEmailMessage.From = New MailAddress("tester@gmail.com")
AnEmailMessage.To.Add("mymail@xxxxx.com")
AnEmailMessage.Subject = "this is test subject"
AnEmailMessage.Body = "this is test body"
AnEmailMessage.Priority = MailPriority.High
Dim SimpleSMTP As New SmtpClient("smtp.gmail.com")
With SimpleSMTP
.Port = 587
.EnableSsl = True
.Credentials = _
New NetworkCredential("tester@gmail.com", "Tester123")
.Send(AnEmailMessage)
End With
MsgBox("Email sent")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
失败时一切正常,我的问题是,如何获取这些控制台消息并在邮件消息中发送?