Contoh Aplikasi Send Mail
Adapun source code untuk vb.net-nya :
03 | 'This will contain the actual message data to send. |
04 | Dim message As System.Net.Mail.MailMessage |
06 | 'The Simple Mail Tranfer Protocol client with the Host and Port number to use. You will |
07 | 'want to change these settings to what you need to use. The host, smtp.gmail.com and port |
08 | 'will work if you have a gmail account. |
09 | Dim smtp As New System.Net.Mail.SmtpClient( "smtp.gmail.com" , 587 ) |
11 | 'Will contain the attachment info to send with the message. |
12 | Dim attach As System.Net.Mail.Attachment |
15 | Private Sub btnAttach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAttach.Click |
17 | 'Create a openDialog object to be able to select a attachment to the mail message. |
18 | Dim openDLG As New OpenFileDialog |
20 | openDLG.AddExtension = True |
21 | openDLG.ReadOnlyChecked = True |
22 | openDLG.Title = "Select the file you want added to the message..." |
24 | If openDLG.ShowDialog = Windows.Forms.DialogResult.OK Then |
26 | txtAttachment.Text = openDLG.FileName |
28 | attach = New System.Net.Mail.Attachment(openDLG.FileName) |
34 | Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click |
36 | 'Setup the mail message with the info in the textboxes... |
37 | message = New System.Net.Mail.MailMessage(txtFrom.Text, txtTo.Text, _ |
38 | txtSubject.Text, txtMessage.Text) |
40 | 'Need to make sure the attachment exists before adding it to the message. |
41 | If My.Computer.FileSystem.FileExists(txtAttachment.Text) Then _ |
42 | message.Attachments.Add(attach) |
44 | 'Use Secure Socket Layer to Encrypt the connection for sending the mail. This needs |
45 | 'be set to "True" if you plan on using GMail as your host. |
48 | 'Setup your account information for authorization... |
49 | smtp.Credentials = New System.Net.NetworkCredential(txtUserName.Text, _ |
54 | 'Send the mail message that was setup. |
57 | 'Usually it was successful in sending the message if it makes it to here :) |
58 | 'Otherwise it should throw a error message from the Catch exception below . |
59 | MessageBox.Show( "Well, the mail message appears to have been a success!" , _ |
60 | " Successful?" , MessageBoxButtons.OK, MessageBoxIcon.Information) |
62 | Catch exc As Net.Mail.SmtpException |
64 | MessageBox.Show(exc.StatusCode.ToString, " Something Happened?" , _ |
65 | MessageBoxButtons.OK, MessageBoxIcon.Error) |
Semoga bisa diterapkan diaplikasi vb.net teman-teman. Sekali lg program aplikasi ini menggunakan
GMAIL credentials!
Source: http://herosetyanofario.wordpress.com/
HOT INFO
Anda ingin mencari refrensi dan contoh program lengkap ? Kami ada. Sekarang Anda bisa mencari PDF Visual Basic di situs ini : www.panduanSkripsi.net. Koleksi program lengkap di sana, proyek PHP dan MySQL, juga jQuery dan Framework. Bukunya juga ada.
No comments:
Post a Comment