在VB中實現發送郵件的功能,可以使用SMTP協議來發送郵件。可以按照以下步驟來實現:
Imports System.Net.Mail
Dim smtpServer As New SmtpClient("smtp.example.com")
smtpServer.Port = 25
smtpServer.Credentials = New Net.NetworkCredential("username", "password")
Dim mail As New MailMessage()
mail.From = New MailAddress("sender@example.com")
mail.[To].Add("receiver@example.com")
mail.Subject = "郵件主題"
mail.Body = "郵件正文"
mail.Attachments.Add(New Attachment("C:\path\to\file.txt"))
smtpServer.Send(mail)
完整的示例代碼如下:
Imports System.Net.Mail
Public Sub SendEmail()
Dim smtpServer As New SmtpClient("smtp.example.com")
smtpServer.Port = 25
smtpServer.Credentials = New Net.NetworkCredential("username", "password")
Dim mail As New MailMessage()
mail.From = New MailAddress("sender@example.com")
mail.[To].Add("receiver@example.com")
mail.Subject = "郵件主題"
mail.Body = "郵件正文"
smtpServer.Send(mail)
End Sub
請注意替換示例代碼中的SMTP服務器地址、端口、用戶名、密碼、發送方地址和接收方地址為實際的值。