How can I send HTML email?

19 visualizaciones (últimos 30 días)
Cristian Urrutia
Cristian Urrutia el 27 de Sept. de 2016
Respondida: Cristian Urrutia el 28 de Sept. de 2016
Is there a way to set the content type to HTML instead of text/plain? I've created my HTML message into a Var and I'm trying to send it via sendmail, but the message is not received as expected. The mail app is just showing the HTML code truncated as if it where a plain text mail. How can I fix the content-type header? Example:
  2 comentarios
Cristian Urrutia
Cristian Urrutia el 27 de Sept. de 2016
Editada: Cristian Urrutia el 27 de Sept. de 2016
public MessagePart(java.lang.String name,
java.lang.String filename,
java.lang.String content_type,
java.lang.String encoding)
Cristian Urrutia
Cristian Urrutia el 27 de Sept. de 2016
This is the code occupied to send the mail:
title_mail='Mail title';
msg_mail=sprintf('<html>...</html>');
%atch_mail='';
mail = 'account@outlook.com'; %Outlook email address
password = 'password'; %Outlook password
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server','smtp-mail.outlook.com');
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','587');
props.remove('mail.smtp.socketFactory.class');%outlook 587 starttls
props.setProperty('mail.smtp.starttls.enable', 'true' );%outlook 587 starttls
props.setProperty('java.lang.String.content_type','text/html')
sendmail('destination@gmail.com',title_mail,msg_mail);%,atch_mail);

Iniciar sesión para comentar.

Respuesta aceptada

Cristian Urrutia
Cristian Urrutia el 28 de Sept. de 2016
I solved this patching the sendmail.m source like this:
msg.setContent(body, 'text/html; charset=utf-8');
Instead:
msg.setText(body, charset);

Más respuestas (0)

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by