I found another cool way of doing this:
vb
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim SendMessage As New Net.Mail.SmtpClient
Dim userToken As New Object
Dim EmailMessage As New MailMessage
With EmailMessage
.From = New MailAddress(cbxFrom.Text)
.To.Add(cbxTo.Text)
.Subject = tbSubject.Text
.Body = tbBody.Text
.Attachments.Add(New Attachment(tbAttachment.Text))
End With
AddHandler SendMessage.SendCompleted, AddressOf SendMessage_SendCompleted
With SendMessage
.Host = cbxSMTPServer.Text
.Port = 25
.UseDefaultCredentials = False
.Credentials = New Net.NetworkCredential("username", "password")
.EnableSsl = False
End With
'SendMessage.SendAsync(cbxFrom.Text, cbxTo.Text, tbSubject.Text, tbBody.Text, userToken)
SendMessage.SendAsync(EmailMessage, userToken)
I am using the MailMessage class to do this.
.SendAsync(MailMessage, Object), one of the way to send mail asynchronously.
MailMessage.To is a readonly property, which can be added using .To.Add() method, input is as String.
MailMessage.From is also a readonly property, create a new instance of MailAddress(input as String)
MailMessage.Attachments, is also a readonly property, use .Attachments.Add() method, input as String
Question is... how do I use Do Until Loop statement to repeat this process:
MailMessage.Attachment.Add() and MailMessage.To.Add() if users have multiple attachments and addresses to mail to... How
vb
Do Until 'what condition should I write here to know it is the end of address and attachments input by user?'
...
Loop