1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.mail
Partial Class recuperermotdepasse
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' On prépare le mail à envoyer
Dim MonMail As New Mail("MonMail", "oscar.leaderweb@gmail.com", "UnCopain", "oscar.leaderweb@gmail.com", "Le sujet de mon mail", "Le corp du message qui peut être en HTML si on set ""isHTML"" à True", False)
' On envoi le mail
MonMail.Send() ' Si le mail est parti, renvoi True sinon, False
End Sub
Public Class Mail
Private _Mail As New System.Net.Mail.MailMessage
Public Sub New(ByVal FromName As String, ByVal FromMail As String, ByVal ToName As String, ByVal ToMail As String, ByVal Subject As String, ByVal Body As String, Optional ByVal isHTML As Boolean = False)
_Mail.Subject = Subject
_Mail.Body = Body
_Mail.From = New System.Net.Mail.MailAddress(FromMail, FromName)
_Mail.To.Add(New System.Net.Mail.MailAddress(ToMail, ToName))
_Mail.IsBodyHtml = isHTML
_Mail.BodyEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")
_Mail.SubjectEncoding = System.Text.Encoding.GetEncoding("iso-8859-1")
End Sub
Public Function Send() As Boolean
'Try
Dim smtp As New System.Net.Mail.SmtpClient("smtp.gmail.com") ' Mettez ici le server SMTP
smtp.Send(_Mail)
Return True
'Catch ex As Exception
Return False
'End Try
End Function
End Class
End Class |
Partager