ASP.net 如何实现发mail给多人,并带附件

和VB.net基本一样

不过还是分开来记录比较好点,呵呵!

界面:

后台代码:

Partial Class TestMail
    Inherits System.Web.UI.Page
    Dim maillist As String
    Dim mSplit As Array
    Dim mlist As New ArrayList
    Dim mMailAddr As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub



    Private Sub send_mail(ByVal strSubject As String, ByVal mFile As String)

       
        Dim madFrom As New System.Net.Mail.MailAddress(txtfrom.Text.Trim) '寄件人
        '  Dim madFrom As New System.Net.Mail.MailAddress(Environment.UserName & "@cn.flextronics.com") '寄件人
        Dim smt As New System.Net.Mail.SmtpClient() 'SMTP Server
        smt.Host = txtserver.Text.Trim '發信主機名稱
        Dim mms As New System.Net.Mail.MailMessage
        mms.From = madFrom
        mms.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8")
        mms.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8")
        Call sMail_list(mms)
        mms.Subject = strSubject.Replace(Chr(10), "").Replace(Chr(13), "") '信件主旨
        mms.Body = "Dear All: <br>  Test Mail for web send" '信件內容
        Dim attach As System.Net.Mail.Attachment = New Net.Mail.Attachment(txtattach.Text)
        mms.Attachments.Add(attach)
        mms.IsBodyHtml = True

        Try
            smt.Send(mms)

            Response.Write("<script>alert('發送成功');</script>")

        Catch ex As Exception

        Finally

            mms.Dispose()
        End Try

    End Sub
    Sub sMail_list(ByVal colAddrs As System.Net.Mail.MailMessage)


        'Dim mMailAddr As String
        Dim NewPath As String = Environment.CurrentDirectory
        Dim i, j As Integer

        ' Dim MMEN As Integer
        Dim mstring As String

        maillist = txtto.Text.Trim
        mSplit = Trim(maillist.ToLower).Split(",")

        If mSplit.Length > 0 Then
            For j = 0 To mSplit.Length - 1
                If mSplit(j).ToString.Trim <> "" Then
                    If InStr(mSplit(j).ToString.Trim, "@") = 0 Then
                        mSplit(j) &= "@hotmail.com"
                    End If
                    mlist.Add(mSplit(j).ToString.Trim)
                End If
            Next
        End If
        If mlist.Count <> 0 Then
            For i = 0 To mlist.Count - 1
                mMailAddr = Trim(mlist.Item(i))
                If mMailAddr.Trim <> "" Then
                    If InStr(mMailAddr, "@") = 0 Then
                        mMailAddr &= "@hotmail.com"
                    End If
                    colAddrs.To.Add(mMailAddr)
                End If
            Next
        End If


       
        colAddrs.To.Add("charycheng@arimacomm.com.cn")

    End Sub

    Protected Sub btnsend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsend.Click
        Dim strsubject As String = txtsubject.Text
        send_mail(strsubject & Now, "Hello<br>" & Now & "<br>Comput Name :" & My.Computer.Name)

    End Sub
End Class


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cheug

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值