none
如何实现一键就可以把我想发送的信息发送给指定的邮箱?? RRS feed

答案

  • 你好,

    你可以尝试一下下面这个例子,它能实现你想要的功能。请参考:

    Imports System.Net.Mail

    Imports System.Net

     

    Public Class Form1

     

        Public Sub emailSend(ByRef toAddr As String, ByRef frAddr As String, ByVal Subj As String, ByVal body As String)

            Dim message As New MailMessage()

            Dim frAddr1 As New MailAddress(frAddr)

            Dim client As New SmtpClient

            Try

                message.To.Add(toAddr)

                message.From = frAddr1

                message.Subject = Subj

                message.Body = body

     

                client.Host = "smtp.live.com"

                client.Credentials = New NetworkCredential(frAddr, "password")

     

                client.EnableSsl = True

                client.Send(message)

                ' client.UseDefaultCredentials = True

                MessageBox.Show("OK")

                message = Nothing

                frAddr = Nothing

                client = Nothing

            Catch ex As Exception

                MessageBox.Show("Error: " & ex.Message, "Email Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

                message = Nothing

                frAddr = Nothing

                client = Nothing

            End Try

    End Sub

     

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            emailSend("email you want to send to", "email you send from", "subject", "body")

    End Sub

     

    End Class

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2010年12月21日 6:36

全部回复

  • 你好,

    你可以尝试一下下面这个例子,它能实现你想要的功能。请参考:

    Imports System.Net.Mail

    Imports System.Net

     

    Public Class Form1

     

        Public Sub emailSend(ByRef toAddr As String, ByRef frAddr As String, ByVal Subj As String, ByVal body As String)

            Dim message As New MailMessage()

            Dim frAddr1 As New MailAddress(frAddr)

            Dim client As New SmtpClient

            Try

                message.To.Add(toAddr)

                message.From = frAddr1

                message.Subject = Subj

                message.Body = body

     

                client.Host = "smtp.live.com"

                client.Credentials = New NetworkCredential(frAddr, "password")

     

                client.EnableSsl = True

                client.Send(message)

                ' client.UseDefaultCredentials = True

                MessageBox.Show("OK")

                message = Nothing

                frAddr = Nothing

                client = Nothing

            Catch ex As Exception

                MessageBox.Show("Error: " & ex.Message, "Email Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

                message = Nothing

                frAddr = Nothing

                client = Nothing

            End Try

    End Sub

     

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            emailSend("email you want to send to", "email you send from", "subject", "body")

    End Sub

     

    End Class

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2010年12月21日 6:36