Thursday, April 15, 2010

Mengirim Email Lewat VB6.0 Menggunakan Vbsendmail.dll

Di bawah ini merupakan contoh kode untuk mengirim email lewat VB6.0 menggunakan bantuan ActiveX (vbSendMail.dll). VB SendMail merupakan ActiveX yang digunakan untuk mengirim email, terdokumentasi dengan baik dan lengkap. Anda dapat memperoleh komponen tersebut di freevbsource.com silakan Anda kunjungi situsnya.
Option Explicit

Private WithEvents poSendMail As vbSendMail.clsSendMail
Private bSendFailed As Boolean

Private Sub Command1_Click()
Dim lCount As Long
Dim lCtr As Long
Dim t!

Command1.Enabled = False
bSendFailed = False
lstStatus.Clear
lblTime.Caption = ""
Screen.MousePointer = vbHourglass

With poSendMail
.SMTPHost = "smtp.telkom.net"
.From = txtSender.Text
.FromDisplayName = txtName.Text
.Message = txtMsg.Text
.AsHTML = True
t! = Timer
.Recipient = txtRecipient.Text
RecipientDisplayName = txtRecName.Text
.Subject = txtSubject.Text
lblTime = "Sending message " & Str(lCtr)
.Send
End With

If Not bSendFailed Then lblTime.Caption = Str(lCount) & " Messages sent in " & Format$(Timer - t!, "#,##0.0") & " seconds."
Screen.MousePointer = vbDefault
Command1.Enabled = True
End Sub

Private Sub Form_Load()
Set poSendMail = New clsSendMail
End Sub

Private Sub poSendMail_Progress(lPercentCompete As Long)
lblProgress = lPercentCompete & "% complete"
End Sub

Private Sub poSendMail_SendFailed(Explanation As String)
MsgBox ("Your attempt to send mail failed for the following reason(s): " & vbCrLf & Explanation)
bSendFailed = True
lblProgress = ""
lblTime = ""
End Sub

Private Sub poSendMail_SendSuccesful()
lblProgress = "Send Successful!"
End Sub

Private Sub poSendMail_Status(Status As String)
lstStatus.AddItem Status
lstStatus.ListIndex = lstStatus.ListCount - 1
lstStatus.ListIndex = -1
End Sub
Download: Source Code