Pessoal,
É o seguinte, estou desenvolvendo uma rotina que captura uma página WEB e envia essa página por e-mail.
Até ai, tranquilo, na verdade to tendo que relembrar o que fiz, porque isso já tinha feito a um tempo.
Meu desafio está sendo no seguinte: Atualmente colocaram um applet nessa página, e preciso que a imagem desse applet vá também no e-mail, como uma figura estática mesmo. O detalhe é que tem que aparecer nesse e-mail.
O código que estou usando até o momento é esse:import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.mail.Authenticator;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
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;
import javax.mail.util.ByteArrayDataSource;
public class SendMail {
public static void main(String[] args) throws Throwable {
Properties mProps = new Properties();
mProps.put("mail.smtp.host", "mail.cl01.mobimail.com");
mProps.put("mail.smtp.port", "465");
mProps.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
mProps.put("mail.smtp.Provider", "com.sun.net.ssl.internal.ssl.Provider");
mProps.put("mail.smtp.auth", "true");
SimpleAuth auth = new SimpleAuth("[email removido]","endrigo@1312");
Session session = Session.getInstance(mProps, auth);
MimeMessage msg = new MimeMessage(session);
InternetAddress from = new InternetAddress("[email removido]");
InternetAddress to = new InternetAddress("[email removido]");
msg.setFrom(from);
msg.addRecipient(Message.RecipientType.TO, to);
msg.setSubject("TESTE");
Multipart mp = new MimeMultipart("alternative");
String textfile = "C:/Temp/teste.txt";
BodyPart bp1 = getFileBodyPart(textfile, "text/plain");
mp.addBodyPart(bp1);
String htmlfile = "C:/Temp/teste.html";
BodyPart bp2 = getFileBodyPart(htmlfile, "text/html");
mp.addBodyPart(bp2);
msg.setContent(mp);
Transport.send(msg);
}
private static BodyPart getFileBodyPart(String arquivo, String contentType) throws FileNotFoundException, MessagingException, IOException {
MimeBodyPart mbp = new MimeBodyPart();
mbp.setDataHandler(new DataHandler(new ByteArrayDataSource(new FileInputStream(arquivo), contentType)));
return mbp;
}
}
class SimpleAuth extends Authenticator {
public String username = null;
public String password = null;
public SimpleAuth(String user, String pwd) {
username = user;
password = pwd;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,password);
}
}
Alguém tem alguma "luz"? to achando que vou ter que fazer uma POG forte pra conseguir isso!!