Send Mail System.Net.Mail
Lo snippet seguene invia e-mail mediante l'utilizzo dell'oggetto System.Net.Mail.
Il codice sorgente è in VB, ma le classi si possono usare tranquillamente anche in C#.
Sub InviaMail()
Try
Dim _smtp As String = "127.0.0.1"
Dim _client As SmtpClient = Nothing
![]()
Dim _mail As MailMessage = New MailMessage()
![]()
If _smtp <> "" Then
_client = New SmtpClient(_smtp)
Else
_client = New SmtpClient()
End If
![]()
'MITTENTE
Dim _from As MailAddress = New MailAddress("mittente@dominio.it", "Nome Cognome")
_mail.From = _from
![]()
'DESTINATARIO / I
_mail.To.Add("destinatario@dominio.it")
![]()
'FORMATO MAIL
_mail.IsBodyHtml = True
![]()
'OGGETTO MAIL
_mail.Subject = "test smtp"
![]()
'BODY
_mail.Body = "Test smtp"
![]()
_client.Send(_mail)
![]()
Catch ex As Exception
Response.Write(ex.ToString())
End Try
![]()
End Sub
Download source send_Mail_System_Net_Mail.zip (733,00 bytes)
Lascia un commento