### EMail example

Simple example of sending an EMail using the jNet library
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private tfTo As TextField
Private tfSubject As TextField
Private btnSend As Button
Private smtpMail As SMTP 'Using jNet library
Private taHTMLBody As TextArea
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main")
MainForm.SetFormStyle("UTILITY")
MainForm.Resizable = False
MainForm.Title = "B4J HowTo - EMail Example"
MainForm.Show
'
tfTo.Text = "toemailaddress"
tfSubject.Text = "B4J EMail Send Test"
taHTMLBody.Text = "

This is the email body.

" & _
"

Regards

"
End Sub`
`Sub SendMail
smtpMail.Initialize("SERVER", "PORT", "USERNAME", "PASSWORD", "SMTPMail")
smtpMail.HtmlBody = True
smtpMail.To.Add(tfTo.Text)
smtpMail.Subject = tfSubject.Text
smtpMail.Body = taHTMLBody.Text
smtpMail.Send
End Sub`
`Sub btnSend_Action
SendMail
End Sub`
`Sub SMTPMail_MessageSent(Success As Boolean)
If Success Then
Log("EMail sent")
Else
Log("EMail Error:" & LastException.Message)
End If
End Sub`
Layout
Simple B4J Visual Designer layout with nodes:
TextField tfTo
TextField tfSubject
TextArea taBody
Button btnSend

Changed: , Category: EMail, File: T6C189M1361.htm, ID: 1361