SiteMap  | About    

VB.NET Email Attachment

The System.Net classes uses to communicate with other applications by using the HTTP, TCP, UDP, Socket etc. Microsoft .Net languages uses System.Net.Mail namespace for sending email . From the previous chapters we learned how to send an email with a text body. Here we are trying to send an eamil with attachment.

The following VB.NET source code shows how to send an email with an attachment from a Gmail address . The Gmail SMTP server name is and the port using send mail is 587 . Here using NetworkCredential for password based authentication.

  1. SmtpServer.Port = 587
  2. SmtpServer.Credentials = New System.Net.NetworkCredential("username", "password")
  3. SmtpServer.EnableSsl = True

Imports System.Net.Mail

	Public Class Form1

		Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
			Dim mail As New MailMessage()
			Dim SmtpServer As New SmtpClient("")
			mail.From = New MailAddress("")
			mail.Subject = "Test Mail - 1"
			mail.Body = "mail with attachment"

			Dim attachment As System.Net.Mail.Attachment
			attachment = New System.Net.Mail.Attachment("your attachment file")

			SmtpServer.Port = 587
			SmtpServer.Credentials = New System.Net.NetworkCredential("username", "password")
			SmtpServer.EnableSsl = True

			MessageBox.Show("mail Send")
		End Sub
	End Class (C) 2019    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.