本文介紹了使用 Header.vb.net 以表格格式發送到電子郵件(Outlook)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
這是我上一個問題的延續 如何使用 vb.net 將 SQL Server 數據庫中的選定項目發送到電子郵件(Outlook)
This is a continuation from my previous question How to send to email (outlook) the selected items in SQL Server database using vb.net
現在我可以發送了,但是格式不太好理解,所以我想把數據以表格格式發送到電子郵件中,并帶有標題,這樣很容易理解.
Now I can send it but the format is not easy to understand so I want to send data to email in table format with header, So that it is easy to understand.
這是我現在所擁有的:
'load the equipment on schedule on the 2nd table
Public Sub OnSchedule()
Dim conn As New SqlConnection("SERVER=L4SMTDB01\SMTDBS02;database = SMT_IT; user=sa;pwd=qwerty; ")
conn.Open()
Dim cmd As SqlCommand = conn.CreateCommand
cmd.CommandText = String.Format("select PatientName,Gender,ScheduleDate,PersonInCharge from " _
& "Schedule where ScheduleDate = CONVERT(date,getdate()) order by ScheduleDate")
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
Dim dtSerial As New DataTable
dtSerial.Load(dr)
dgvOnSchedule.DataSource = dtSerial
Else
MsgBox("no data")
End If
dr.Close()
conn.Close()
End Sub
'send email
Public Sub sendEmail()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()
oMail.To = New AddressCollection("emil@calcomp.co.th")
oMail.Cc = New AddressCollection("emil@calcomp.co.th,chokchai@calcomp.co.th")
oMail.Subject = "Patient Schedule today"
'send to email not in the table.
Dim sb As New System.Text.StringBuilder()
For Each row As DataGridViewRow In dgvOnSchedule.Rows
For Each cell As DataGridViewCell In row.Cells
sb.Append(cell.Value)
sb.Append("||")
Next
Next
oMail.TextBody = "" & sb.ToString()
Dim oServer As New SmtpServer("mailpe.calcomp.co.th")
Try
oSmtp.SendMail(oServer, oMail)
MessageBox.Show("send to email success")
Catch ex As Exception
MessageBox.Show("no success")
End Try
End Sub
End Class
推薦答案
我在電子郵件方法中編輯我的代碼如下:我將 sb 的值放在表中.
I edit my code in Email Methods as below: I put the value of sb inside the table.
'send email method
Public Sub sendEmail()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()
oMail.HtmlBody = True
oMail.To = New AddressCollection("emil@calcomp.co.th")
oMail.Cc = New AddressCollection("emil@calcomp.co.th,chokchai@calcomp.co.th")
oMail.Subject = "FIXTURE ON SCHEDULE"
Dim sb As New StringBuilder("<table width='1000px' align='center' border='1' cellpadding='20' cellspacing='0' style='border'top:5px solid white;> " & _
" <tr><th>PatientName</th> <th>Gender</th> <th>ScheduleDate</th> <th>PersonIncharge")
For Each row As DataGridViewRow In dgvOnSchedule.Rows
sb.Append("<tr>")
For Each cell As DataGridViewCell In row.Cells
sb.Append("<td>")
sb.Append(cell.Value)
sb.Append("</td>")
Next
sb.Append("</tr>")
Next
sb.Append("</table>")
oMail.HtmlBody = sb.ToString()
Dim oServer As New SmtpServer("mailpe.calcomp.co.th")
Try
oSmtp.SendMail(oServer, oMail)
MessageBox.Show("send to email success")
Catch ex As Exception
MessageBox.Show("no success")
End Try
End Sub
這篇關于使用 Header.vb.net 以表格格式發送到電子郵件(Outlook)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!