' Objet SMTP
Dim LSMTPServer As SmtpClient = New SmtpClient("smtp.gmail.com", 587)
'
' Nom d'utilisateur et Mot de passe (toto@gmail.com, ne mettre que l'identifiant situé avant le @)
LSMTPServer.Credentials = New Net.NetworkCredential("toto", "azerty")
' Hote
LSMTPServer.Host = "smtp.gmail.com"
' Port
LSMTPServer.Port = 587
' Le serveur SMTP nécessite une connexion cryptée (SSL) ?
LSMTPServer.EnableSsl = True
'
'
' Définition du message-----------------------------------------------
Dim LMail As MailMessage = Nothing
LMail = New MailMessage()
'
' Expéditeur
LMail.From = New MailAddress("robert@yahoo.com")
'
' Sujet du mail
LMail.Subject = "News"
'
' Format du mail : - HTML (=True)
' - Texte (=False)
LMail.IsBodyHtml = True
'
' Corps du message du mail
Dim LMessage As String = "METTRE LE MESSAG EN HTML" & "<BR>" & "NOUVELLE LIGNE" & "<BR>" & "AUTRE NOUVELLE LIGNE"
Dim LHTML As String = vbnullstring
LHTML = LHTML & "<html>"
LHTML = LHTML & "<body>"
LHTML = LHTML & "<font face=Courier New size=-1>"
If (LMessage <> vbNullString) Then
LHTML = LHTML & LMessage & "<br><br>"
End If
LHTML = LHTML & "</font>"
LHTML = LHTML & "</body>"
LHTML = LHTML & "</html>"
LMail.Body = LHTML
'
'
' Envoi du message----------------------------------------------------
Try
'
LSMTPServer.Send(LMail)
'
Catch Ex_SendMail As Exception
'
' Une exception a été levée. Liste ci-dessous :
'http://www.xequte.com/support/maillistking/smtperrors.html
'
Dim LErreur = Ex_SendMail.Message
If (Ex_SendMail.InnerException IsNot Nothing) Then
LErreur = LErreur & " / " & Ex_SendMail.InnerException.Message
End If
End Try