| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 网络编程 >> 实例分析正文
最新推荐 更多内容
VB.Net邮件发送[带附件]的实例
VB.Net邮件发送[带附件]的实例
作者:Ilu    来源:乐博网     更新时间:2009-11-1

VB.Net邮件发送[带附件]的实例

代码:

乐博网lob.cn提示:调试环境为 vs2005 +  windows2003 / windows2008 / xp / vista + .NET Framework 2.0

Imports System.Net.Mail
Imports System.Net
Public Class MailForm
    Dim message As MailMessage
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SendSMTPEMail()
    End Sub
    Sub SendSMTPEMail()
        Dim client As System.Net.Mail.SmtpClient = New Net.Mail.SmtpClient
        client.UseDefaultCredentials = False
        client.Credentials = New System.Net.NetworkCredential(ComboBox3.Text, TextBox3.Text) ''用户名,密码
        client.DeliveryMethod = SmtpDeliveryMethod.Network
        client.Host = ComboBox1.Text
        If InStr(ComboBox3.Text, "@", CompareMethod.Text) <= 0 Or ComboBox3.Text.Length <= InStr(ComboBox3.Text, "@", CompareMethod.Text) Then
            MessageBox.Show("乐博网提示:源邮件地址错误!")
        ElseIf InStr(ComboBox2.Text, "@", CompareMethod.Text) <= 0 Or ComboBox2.Text.Length <= InStr(ComboBox2.Text, "@", CompareMethod.Text) Then
            MessageBox.Show("乐博网提示:目标邮件地址错误!")
        Else
            message = New System.Net.Mail.MailMessage(ComboBox3.Text, ComboBox2.Text, TextBox2.Text, RichTextBox1.Text)
            message.BodyEncoding = System.Text.Encoding.UTF8
            message.IsBodyHtml = True
            If TextBox1.Text.Trim <> "" Then  ''带附件  
                If Dir(TextBox1.Text.Trim) = "" Then
                Else
                    Dim attach As Net.Mail.Attachment = New Net.Mail.Attachment(TextBox1.Text)
                    message.Attachments.Add(attach)
                End If
            End If
            client.Send(message)
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = OpenFileDialog1.FileName
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()

    End Sub
End Class

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    发送邮件实例(VB2010实例)

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]