Pessoal, criei uma aplicação para envio de e-mail com um WMV no corpo da mensagem, porém somente funcionou no Outlook Express.
Algum de vocês poderia me ajudar?
Desde já agradeço…
Segue o código:
package br.mailvideo.james.testes;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class TestVideoMail {
private String mailHost = "o Host";
private String mailUser="";
private String mailPass = "";
private String mailFrom = "";
private String mailTo = "";
private String filePath = "c:\\video.wmv";
private void send() {
Session session = null;
Authenticator auth = null;
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", mailHost);
if (mailUser != null && !mailUser.trim().equals("")) {
props.put("mail.smtp.auth", "true");
auth = new SMTPAuthenticator();
}
session = Session.getInstance(props, auth);
try {
// Create the message
Message message = new MimeMessage(session);
// Fill its headers
message.setSubject("Teste Email com video");
message.setFrom(new InternetAddress(mailFrom));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(mailTo));
// Create your new message part
BodyPart messageBodyPart = new MimeBodyPart();
StringBuffer htmlText = new StringBuffer("<H2>Email com vídeo</H2>");
htmlText.append("<html>");
htmlText.append("<body>");
htmlText.append("<div align=center width=100% height=100%><img src=\"imagem.gif\"");
htmlText.append("dynsrc=\"cid:iphone2.wmv\" width=\"320\" height=\"240\" /></div>");
htmlText.append("<b>segundo video</b>");
htmlText.append("<div align=center width=100% height=100%><img src=\"imagem.gif\"");
htmlText.append("dynsrc=\"cid:iphone2.wmv\" width=\"320\" height=\"240\" /></div>");
htmlText.append("</body>");
htmlText.append("</html>");
messageBodyPart.setContent(htmlText.toString(), "text/html");
// Create a related multi-part to combine the parts
MimeMultipart multipart = new MimeMultipart("related");
multipart.addBodyPart(messageBodyPart);
// Create part for the image
messageBodyPart = new MimeBodyPart();
// Fetch the image and associate to part
DataSource fds = new FileDataSource(filePath);
messageBodyPart.setDataHandler(new DataHandler(fds));
messageBodyPart.setHeader("Content-ID","<iphone2.wmv>");
messageBodyPart.setHeader("Content-Type", "video/x-ms-WMV");
// Add part to multi-part
multipart.addBodyPart(messageBodyPart);
// Associate multi-part with message
message.setContent(multipart);
// set the Date: header
message.setSentDate(new Date());
// send the message
Transport.send(message);
} catch (MessagingException mex) {
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
}
}
}
private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username = mailUser;
String password = mailPass;
return new PasswordAuthentication(username, password);
}
}
public static void main(String[] args) {
TestVideoMail mail = new TestVideoMail();
mail.send();
System.out.println(“E-mail enviado com sucesso!”);
}
}