积极答复者
如何实现一键就可以把我想发送的信息发送给指定的邮箱??

问题
答案
-
你好,
你可以尝试一下下面这个例子,它能实现你想要的功能。请参考:
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.
- 已标记为答案 feiyun0112Moderator 2010年12月22日 6:18
全部回复
-
您好
您可以利用 SmtpClient 來發送email,請參考
http://www.dotblogs.com.tw/bauann/archive/2009/04/20/8062.aspx
http://msdn.microsoft.com/zh-cn/library/system.net.mail.smtpclient(v=VS.90).aspx
歡迎參觀我的Blog.NET菜鳥自救會 -
你好,
你可以尝试一下下面这个例子,它能实现你想要的功能。请参考:
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.
- 已标记为答案 feiyun0112Moderator 2010年12月22日 6:18