vb.net 发送电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4862649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:15:58  来源:igfitidea点击:

vb.net send email

vb.netemail

提问by Beginner

I was wondering how I could send an email from within a vb application? Can any one assist in where to begin?

我想知道如何从 vb 应用程序中发送电子邮件?任何人都可以协助从哪里开始?

回答by Morten Anderson

Use the SmtpClient class within the System.Net.Mail namespace

在 System.Net.Mail 命名空间中使用SmtpClient 类

Example.

例子。

'create the mail message
Dim mail As New MailMessage()

'set the addresses
mail.From = New MailAddress("xx@xx")
mail.[To].Add("xx@xx")

'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"

'set the server
Dim smtp As New SmtpClient("localhost")

'send the message
Try
    smtp.Send(mail)
    Response.Write("Your Email has been sent sucessfully - Thank You")
Catch exc As Exception
    Response.Write("Send failure: " & exc.ToString())
End Try

回答by Daniel Casserly

You can use the System.Net.Mailnamespace, look it up and see if it helps. I use C# but I imagine it is similar, create a client, then a message, set params of the message and then client.Send()will send the message.

您可以使用System.Net.Mail命名空间,查找它,看看它是否有帮助。我使用 C#,但我想它是相似的,创建一个客户端,然后创建一条消息,设置消息的参数,然后client.Send()发送消息。