邮件发送示例 (VB.NET 2005)

Imports System.net.Mail
Imports System.Text
Imports System.Security
Imports System.Net.Sockets

Public Class Form1

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chk.CheckedChanged
        If chk.Checked = True Then
            txtName.Enabled = True
            txtPassword.Enabled = True
        Else
            txtName.Enabled = False
            txtPassword.Enabled = False
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Dim mail As New MailMessage()
        mail.From = New MailAddress(txtFrom.Text)
        mail.To.Add(txtTo.Text)
        
        'set the content
        mail.Subject = txtSubject.Text
        mail.Body = txtContent.Text

        ''specify the priority of the mail message
        mail.Priority = MailPriority.High

        'to add custom headers, we use the Headers.Add(...) method to add headers to the 
        '.Headers collection
        mail.Headers.Add("X-Company", "JOHN NG SDN BHD")
        mail.Headers.Add("X-Location", "Malaysia")


        Dim smtp As New SmtpClient(txtSMTP.Text)
        If chk.Checked = True Then            
            smtp.Credentials = New System.Net.NetworkCredential(txtName.Text, txtPassword.Text)
        End If
        Try
            smtp.Send(mail)
            MsgBox("恭喜,邮件已经发送到指定的邮件地址.", MsgBoxStyle.Information, "邮件发送示例")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "邮件发送失败")
        End Try

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub
End Class





引用:http://www.mndsoft.com/blog/article.asp?id=818下载文件 点击下载此文件



文章来自: 本站原创
引用通告地址: http://www.is21.cn/trackback.asp?tbID=339
Tags:
评论: 0 | 引用: 0 | 查看次数: 2810
发表评论
你没有权限发表留言!