Hello, I have the following problem.
I need to send an email through vb.net, everything works correctly until I charge:
File .html (Signature with embedded images)
Content of the textBoxMessage (It is where the user writes the message of the mail body)
Public Sub mailSinAdjunto()
Dim messageSinAdjunto As MailMessage = New MailMessage()
If (txtPara.Text = "" Or txtAsunto.Text = "" Or txtPara.Text = "") Then
MsgBox(mensajeTextosVacios)
Else
'Configuracion del STMP
smtp.Credentials = New Net.NetworkCredential(Login, Password)
smtp.Port = PuertoSMTP.ToString
smtp.Host = ServidorSMTP.ToString
' Configuracion del mensaje
messageSinAdjunto.[To].Add(txtPara.Text)
messageSinAdjunto.From = New MailAddress(DireccionEmailEnvio, NombreMostrar, System.Text.Encoding.UTF8)
messageSinAdjunto.Subject = txtAsunto.Text.ToString
messageSinAdjunto.SubjectEncoding = System.Text.Encoding.UTF8
messageSinAdjunto.Priority = MailPriority.High
If rdbSSL.Checked = True Then
smtp.EnableSsl = True
Else
smtp.EnableSsl = False
End If
If rdbTextoPlano.Checked = True Then
messageSinAdjunto.IsBodyHtml = False
messageSinAdjunto.Body = txtMensaje.Text
ElseIf rdbTextoHtml.Checked = True Then
Dim allMensajeMail As String
messageSinAdjunto.IsBodyHtml = True
allMensajeMail = txtMensaje.Text.ToString
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(textoHtml, Nothing, System.Net.Mime.MediaTypeNames.Text.Html)
Dim imgCorreoBody As LinkedResource = New LinkedResource(logoCorreo, MediaTypeNames.Image.Jpeg)
imgCorreoBody.ContentId = "logoBody"
htmlView.LinkedResources.Add(imgCorreoBody)
Dim imgCorreoHeader As LinkedResource = New LinkedResource(logoCorreo, MediaTypeNames.Image.Jpeg)
imgCorreoHeader.ContentId = "logoHeader"
htmlView.LinkedResources.Add(imgCorreoHeader)
Dim textoMensaje As AlternateView = AlternateView.CreateAlternateViewFromString(allMensajeMail, Nothing, System.Net.Mime.MediaTypeNames.Text.Plain)
messageSinAdjunto.AlternateViews.Add(htmlView)
messageSinAdjunto.AlternateViews.Add(textoMensaje)
End If
Try
smtp.Send(messageSinAdjunto)
listErrores.Text = (mensajeEnviado)
Catch ex As Exception
listErrores.Text = (mensajeNoEnviado & ex.ToString)
addLogArchivo(ex.Message)
End Try
End If
End Sub
When using:
messageSinAdjunto.AlternateViews.Add(htmlView) messageSinAdjunto.AlternateViews.Add(textoMensaje)
If I leave both, only the signature.html appears in the mail. If I put the text message first, only the message appears If I concatenate it, the html appears without forming (the code appears)
What could I use to send both? Thank you !!