Public Sub SendMail(ByVal Filename As String, ByVal dept As String, ByVal remark As String)
iConn.OpenOra(connection)/iConn.OpenSql(connection)
Dim Smtp As New SmtpClient(Mail Server)
Dim attFile As String = "D:\Export\" & Filename
Dim mail As New MailMessage()
If dept = "" Then
cond = "where i_remark ='" & remark & "' "
ElseIf remark = "" Then
cond = "where i_dept ='" & dept & "' "
End If
'set the addresses
Dim strsql As String = "Select I_mail_acc from T_mail_ms " & cond
Dim da As New SqlDataAdapter(strsql, iConn.iConnSql)
Dim dt As New DataTable()
da.Fill(dt)
If dt.Rows.Count <> 0 Then
For i As Integer = 0 To dt.Rows.Count - 1
Dim tomail As String = dt.Rows(i)("I_mail_acc").ToString()
mail.To.Add(tomail)
Next
End If
Smtp.Credentials = New System.Net.NetworkCredential("UserName", "PASSWORD")
'set the content
mail.From = New MailAddress("Email")
mail.Attachments.Add(New Attachment("" & attFile & ""))
mail.Subject = "This is an email"
mail.Body = "Test Email "
Try
Smtp.Send(mail)
MsgBox("Send Mail Complete!")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Dim mail As New MailMessage
Dim SMTP As New SmtpClient("localhost", 25)
mail.From = New MailAddress("[email protected]")
mail.To.Add("[email protected]")
mail.Subject = "Subject Test"
Dim body As New StringBuilder
body.Append("<style type=""text/css"">")
body.Append("<!--")
body.Append(".style1 {")
body.Append(" font-family: ""MS Sans Serif"";")
body.Append(" font-size: 9px;")
body.Append("}")
body.Append(".style2 {")
body.Append(" font-size: 9px;")
body.Append(" font-weight: bold;")
body.Append("}")
body.Append("-->")
body.Append("</style>")
body.Append("5555 Hello")
mail.IsBodyHtml = True
mail.Body = body.ToString()
SMTP.EnableSsl = False
SMTP.Send(mail)
ติดตั้ง SMTP บน Windows 7
ติดตั้ง SMTP Service สำหรับส่งอีเมล์บน Windows 7 (PHP,ASP.Net,IIS,Apache)