Public Class MailHelper
'發送不用驗證的郵件
Public Sub Send(ByVal from As String, ByVal mailto As String, ByVal cc As String, ByVal bcc As String, ByVal subject As String, ByVal body As String, ByVal attachments As String(), ByVal priority As Web.Mail.MailPriority)
Try
Dim x As Int16
Dim mailObj As New System.Web.Mail.MailMessage
With mailObj
.From = from
.To = mailto
.Cc = cc
.Bcc = bcc
.Subject = subject
.BodyFormat = Web.Mail.MailFormat.Html
.BodyEncoding = System.Text.Encoding.UTF8
.Body = body
.Priority = priority
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "0")
End With
'mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") '1要驗證,0是不驗證
'mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "
[email protected]")
'mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "zfnm2015")
If (attachments Is Nothing = False) Then
For x = 0 To attachments.Length - 1
mailObj.Attachments.Add(New Web.Mail.MailAttachment(attachments(x)))
Next
End If
System.Web.Mail.SmtpMail.SmtpServer = "192.168.150.251"
System.Web.Mail.SmtpMail.Send(mailObj)
Catch ex As Exception
Throw ex
End Try
End Sub
Public Sub Send(ByVal from As String, ByVal mailto As String, ByVal cc As String, ByVal subject As String, ByVal body As String, ByVal priority As Web.Mail.MailPriority, ByVal attachments As String())
Send(from, mailto, cc, "", subject, body, attachments, priority)
End Sub
Public Sub Send(ByVal from As String, ByVal mailto As String, ByVal cc As String, ByVal subject As String, ByVal body As String, ByVal attachments As String())
Send(from, mailto, cc, "", subject, body, attachments, Web.Mail.MailPriority.Normal)
End Sub
Public Sub Send(ByVal from As String, ByVal mailto As String, ByVal cc As String, ByVal subject As String, ByVal body As String)
Send(from, mailto, cc, "", subject, body, Nothing, Web.Mail.MailPriority.Normal)
End Sub
End Class