Torna al Thread
Private MITTENTE As String = "rossi.paolo@gmail.com"
Private DESTINATARIO As String = "verdi.maria@gmail.com"
Private PERCORSO_LOGO As String = "C:\img\logo.gif"
Private USERNAME As String = "username@gmail.com"
Private PASSWORD As String = "password@gmail.com"
Private OGGETTO_EMAIL As String = "INVIO EMAIL IN HTML CON IMMAGINE"
Private Sub email()
' Creare il messagio dell'email
Dim email As New MailMessage(MITTENTE, DESTINATARIO)
' Informazioni
email.Subject = OGGETTO_EMAIL
email.IsBodyHtml = True
email.Body = "<div style=""font-family:Arial"">Messaggio prima di includere l'immagine:<br /><br /><img src=""@@IMAGE@@"" alt=""""><br /><br /> Descrizione dell'immagine sopra inserita.</div>"
' Creare il INLINE
Dim attachmentPath As String = PERCORSO_LOGO
' generate the contentID string using the datetime
Dim contentID As String = Path.GetFileName(attachmentPath).Replace(".", "")
Dim inline As New Attachment(attachmentPath)
inline.ContentDisposition.Inline = True
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline
inline.ContentId = contentID
inline.ContentType.MediaType = "image/gif"
' "image/png" ; "image/jpg"
inline.ContentType.Name = Path.GetFileName(attachmentPath)
email.Attachments.Add(inline)
' replace the tag with the correct content ID
email.Body = email.Body.Replace("@@IMAGE@@", "cid:" & contentID)
'Invio email con GMAIL SMTP
Dim credenziali As New System.Net.NetworkCredential(USERNAME.ToString(), PASSWORD.ToString())
Dim smtpClient As New SmtpClient("smtp.gmail.com", 587)
'Se è necessario ed è supportata la cifratura SSL
smtpClient.EnableSsl = True
smtpClient.Credentials = credenziali
Try
smtpClient.Send(email)
email.Dispose()
Catch smtpException As SmtpException
MessageBox.Show([String].Format("SmtpException : {0}", smtpException.Message))
Catch ex As Exception
MessageBox.Show(String.Format("Exception: {0}", ex.Message))
End Try
End Sub