界面
代码
<span style="font-family:KaiTi_GB2312;font-size:24px;">Imports System.Net.Mail Imports System.Text Imports System.Security Imports System.Net.Sockets Public Class frmEmail Private Sub btnSend_Click(sender As Object,e As EventArgs) Handles btnSend.Click '创建邮件 Dim mail As New MailMessage() '发件人邮箱 mail.From = New MailAddress(txtFrom.Text) '如果有多个,可以多次添加 mail.To.Add(txtTo.Text) '邮件主题 mail.Subject = txtSubject.Text '邮件内容 mail.Body = txtContent.Text '指定邮件的优先级 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 chk_CheckedChanged(sender As Object,e As 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 End Class</span>
结果显示
此时我们查看收件人的邮箱: