Tutor ini membahas bagaimana caranya membuat aplikasi krim email ( Smtp-server).
Sebelum dilakukan pengiriman email dilakukan setting smtp server terlebih dahulu.
Pada tutor ini terdiri dari object-object sebagai berikut :
1. Non Visual Object : n_smtp dan n_winsock
2. Visual object : Window konfigurasi dan window email.
3. File pendukung lainnya dapat di download dari forder source code.
Source aplikasi dapat di download di sini.
Aplikasi Jadi dapat di download di sini.
A. N-smtp dan w_winsock dapat diambil dari source code aplikasi dan tambahkan pada project anda.
B. Membuat Window Konfigurasi SMTP-server
1. Buatkan desain seperti tampilan gambar di atas.
2. Buat Variable :
- Global Variable : n_smtp gn_smtp
- GlobalExternalFuntions : Function ULONG GetCurrentDirectoryA(ULONG nBufferLength, ref STRING lpBuffer) library "KERNEL32.dll"
1. Buat fungsi window:
- Fungsi : of_getreg
String ls_regkey, ls_regvalue
ls_regkey = "HKEY_CURRENT_USER\Software\TopWiz\smtp_pop3"
RegistryGet(ls_regkey, as_entry, ls_regvalue)
If ls_regvalue = "" Then
ls_regvalue = as_default
End If
Return ls_regvalue
- Fungsi : of_replaceall
String ls_newstring
Long ll_findstr, ll_replace, ll_pos
// get length of strings
ll_findstr = Len(as_findstr)
ll_replace = Len(as_replace)
// find first occurrence
ls_newstring = as_oldstring
ll_pos = Pos(ls_newstring, as_findstr)
Do While ll_pos > 0
// replace old with new
ls_newstring = Replace(ls_newstring, ll_pos, ll_findstr, as_replace)
// find next occurrence
ll_pos = Pos(ls_newstring, as_findstr, (ll_pos + ll_replace))
Loop
Return ls_newstring
- Fungsi : of_setreg
String ls_regkey
ls_regkey = "HKEY_CURRENT_USER\Software\TopWiz\smtp_pop3"
RegistrySet(ls_regkey, as_entry, as_value)
2. Tombol klik..contoh Setting Gmail:
sle_server.text = "smtp.gmail.com"
sle_port.text = "465"
sle_userid.text = ""
sle_password.text = ""
cbx_smtpauth.checked = True
cbx_smtptls.checked = True
sle_userid.SetFocus()
MessageBox("GMail Settings", &
"Masukan GMail Userid & Password kemudian klik simpan.")
3. Tombol Simpan:
of_setreg("SmtpServer", sle_server.text)
of_setreg("SmtpUserid", sle_userid.text)
of_setreg("SmtpPassword", sle_password.text)
of_setreg("SmtpPort", sle_port.text)
If cbx_smtpauth.checked Then
of_setreg("SmtpAuth", "Y")
Else
of_setreg("SmtpAuth", "N")
End If
If cbx_smtptls.checked Then
of_setreg("SmtpTLS", "Y")
Else
of_setreg("SmtpTLS", "N")
End If
4. Tombol Tutup:
close(parent)
A. Membuat Window Kirim email
1. Variable : sama seperti window konfigurasi .
2. Buatkan Fungsi window pada window ini dengan fungsi yang sama dengan window konfigurasi.
3. Pada Konfigurasi tambahkan sintak:
Open(w_email_setting)
4. Pada tombol Tutup tambahkan sintak :
Close (parent)
5. Pada tombol Kirim mail tambahkan sintak:
String ls_body, ls_server, ls_uid, ls_pwd
String ls_filename, ls_port
Integer li_idx, li_max
Boolean lb_html, lb_Return
UInt lui_port
SetPointer(HourGlass!)
ls_server = of_getreg("SmtpServer", "")
If ls_server = "" Then
MessageBox("Edit Error", &
"Anda harus setting SMTP server dalulu..!!")
Return
End If
If sle_send_email.text = "" Then
MessageBox("Edit Error", &
"Email tujuan harus diisi dulu !")
Return
End If
If sle_from_email.text = "" Then
MessageBox("Edit Error", &
" Email pengirim harus diisi dulu..!")
Return
End If
If sle_subject.text = "" Then
MessageBox("Edit Error", &
"Topik harus diisi dulu..!")
Return
End If
If mle_body.text = "" Then
MessageBox("Edit Error", &
"Isi Pesan harus diisi dulu..!!")
Return
End If
If cbx_sendhtml.Checked Then
ls_body = "<html><body bgcolor='#FFFFFF' topmargin=8 leftmargin=8><h2>"
ls_body += of_replaceall(mle_body.text, "~r~n", "<br>") + "</h2>"
ls_body += "</body></html>"
lb_html = True
Else
ls_body = mle_body.text
lb_html = False
End If
lui_port = Long(of_getreg("SmtpPort", "25"))
// *** set email properties *********************
gn_smtp.of_ResetAll()
gn_smtp.of_SetPort(lui_port)
gn_smtp.of_SetServer(ls_server)
gn_smtp.of_SetReceipt(cbx_receipt.checked)
gn_smtp.of_SetLogFile(cbx_logfile.checked, "smtp_logfile.txt")
gn_smtp.of_SetSubject(sle_subject.text)
gn_smtp.of_SetBody(ls_body, lb_html)
gn_smtp.of_SetFrom(sle_from_email.text, sle_from_name.text)
gn_smtp.of_AddAddress(sle_send_email.text, sle_send_name.text)
// *** set Userid/Password if required **********
If of_getreg("SmtpAuth", "N") = "Y" Then
ls_uid = of_getreg("SmtpUserid", "")
ls_pwd = of_getreg("SmtpPassword", "")
gn_smtp.of_SetLogin(ls_uid, ls_pwd)
End If
// *** add any attachments **********************
li_max = lb_attachments.TotalItems()
For li_idx = 1 To li_max
ls_filename = lb_attachments.Text(li_idx)
gn_smtp.of_AddAttachment(ls_filename)
Next
// *** send the message *************************
If of_getreg("SmtpTLS", "N") = "Y" Then
lb_Return = gn_smtp.of_SendTLSMail()
Else
lb_Return = gn_smtp.of_SendMail()
End If
//If lb_Return Then
// MessageBox("Informasi", "Pesan sudah berhasil dikirim kepada : " +sle_send_email.text )
//Else
// MessageBox("Pengiriman E-mail gagal", gn_smtp.of_GetLastError())
//End If
Close(parent)
Source aplikasi dapat di download di sini.
Aplikasi Jadi dapat di download di sini.
Credit By : Bayu Setiawan
3 komentar:
Wow info dan aplikasi yang bagus ijin sedot gan!! ^^
wah keren nih gan ^^_^^
nyimak dulu deh :D
Posting Komentar