Hello everyone!
I found on the web a class that send a mail with gmail account:
and it's work great!!!
but there is one problem
when i create a button perform the class, the whole program get stuck for a while until the mail send
can i do something to make the class run on background?
I found on the web a class that send a mail with gmail account:
VB.NET:
Public Class MailSender
Public Sub SendMail()
Try
Dim SmtpServer As New System.Net.Mail.SmtpClient()
Dim mail As New System.Net.Mail.MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential("[my gmail]@gmail.com", "[my password]")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
mail = New System.Net.Mail.MailMessage()
mail.From = New System.Net.Mail.MailAddress("[my gmail]")
mail.To.Add("[other mail]")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
and it's work great!!!
but there is one problem
when i create a button perform the class, the whole program get stuck for a while until the mail send
can i do something to make the class run on background?
VB.NET:
Public Class frmSender
Dim m As New MailSender
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
m.SendMail()
End Sub
End Class