VB.NET2013 发邮件

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", "Nienmade@nienmade.com.cn")  
            '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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值