HS Banner
Back
Send email from a VB.Net application

Author: Admin 03/26/2022
Language: Visual Basic .NET
Tags: send email vb.net


Description:

Here's an example of how to send an email in a VB.Net application.

Article:

'create the mail message
                Dim mail As New Net.Mail.MailMessage()

                'set the addresses
                mail.From = New Net.Mail.MailAddress(Email_User)
                mail.To.Add(Email_User)

                'set the content
                mail.Subject = tbSubject.Text
                mail.IsBodyHtml = True
                mail.Body = "Name: " & tbName.Text & "<br />" &
                             "Email: " & tbEmail.Text & "<br />" &
                             "Phone: " & tbPhone.Text & "<br />" & "<br />" &
                             "Category: " & ddlCategory.SelectedValue & "<br />" & "<br />" &
                             "Message: " & ASPxHtmlEditor1.Html

                ' Create the file attachment for this e-mail. 
                'mail.Attachments.Add(New System.Net.Mail.Attachment(Environment.CurrentDirectory & "\Log.txt"))

                'send the message
                Dim smtp As New Net.Mail.SmtpClient(Email_Server)
                'Server Port
                smtp.Port = Email_Port

                'to authenticate we set the username and password properties on the SmtpClient
                smtp.Credentials = New Net.NetworkCredential(Email_User, Email_Password)
                'Send email
                smtp.Send(mail)

                'Clean up
                smtp.Dispose()
                mail.Dispose()



Back
Comments
Add Comment
There are no comments yet.