Sending Email Dengan Aplikasi VB.Net

Tahun 2011 sudah hampir berakhir yah teman-teman sekalian. Rasa-rasanya baru beberapa bulan lalu tahun baru 2011 berakhir. Dan nga kerasa udah mau tahun baru lagi menuju 2012. Resolusi tahunan memang harus menjadi salah satu patokan dalam menilai berhasil atau tidaknya segala tindakan yang kita lakukan 12 bulan belakangan.

Anyway udah lama rasanya gw nga buat sharing info untuk buat teman-teman sekalian. Kali ini gw mau sharing mengenai sending email melalui aplikasi menggunakan gmail credentials. Berikut ini gw lampirin contoh aplikasinya :

Contoh Aplikasi Send Mail

Adapun source code untuk :

 Public Class frmMain
'This will contain the actual message data to send.
Dim message As System.Net.Mail.MailMessage
'The Simple Mail Tranfer Protocol client with the Host and Port number to use. You will
'want to change these settings to what you need to use. The host, and port
'will work if you have a gmail account.
Dim smtp As New System.Net.Mail.SmtpClient("", 587)
'Will contain the attachment info to send with the message.
Dim attach As System.Net.Mail.Attachment
Private Sub btnAttach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAttach.Click
'Create a openDialog object to be able to select a attachment to the mail message.
Dim openDLG As New OpenFileDialog

openDLG.AddExtension = True
openDLG.ReadOnlyChecked = True
openDLG.Title = "Select the file you want added to the message..."

If openDLG.ShowDialog = Windows.Forms.DialogResult.OK Then

txtAttachment.Text = openDLG.FileName

attach = New System.Net.Mail.Attachment(openDLG.FileName)

End If

End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
'Setup the mail message with the info in the textboxes...
message = New System.Net.Mail.MailMessage(txtFrom.Text, txtTo.Text, _
txtSubject.Text, txtMessage.Text)
'Need to make sure the attachment exists before adding it to the message.
If My.Computer.FileSystem.FileExists(txtAttachment.Text) Then _
'Use Secure Socket Layer to Encrypt the connection for sending the mail. This needs
'be set to "True" if you plan on using GMail as your host.
smtp.EnableSsl = True
'Setup your account information for authorization...
smtp.Credentials = New System.Net.NetworkCredential(txtUserName.Text, _

'Send the mail message that was setup.
'Usually it was successful in sending the message if it makes it to here🙂
'Otherwise it should throw a error message from the Catch exception below.
MessageBox.Show("Well, the mail message appears to have been a success!", _
"  Successful?", MessageBoxButtons.OK, MessageBoxIcon.Information)

Catch exc As Net.Mail.SmtpException

MessageBox.Show(exc.StatusCode.ToString, "  Something Happened?", _
MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End Sub

End Class

Semoga bisa diterapkan diaplikasi teman-teman. Sekali lg program aplikasi ini menggunakan GMAIL credentials!

Thanks to : Jason Hensley

Webpage:  & &

Tagged , , , ,

4 thoughts on “Sending Email Dengan Aplikasi VB.Net

  1. alfred beilin says:

    hi there happy new year to yous all

  2. I like looking at your blog posts, Sending Email Dengan Aplikasi VB.Net Herosetya Nofario has been added to my favorites in firefox.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: