class SendmailExample {
public SendmailExample() throws NoSuchProviderException, MessagingException {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("abgorn", "***********");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("abgorn@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("abgorn@hotmail.com"));
message.setSubject("Testing");
message.setText("Shut up foo'!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
It does send an email from my Gmail account to my Hotmail but also the Gmail (even though it's sending from that account). I don't want this to happen. At first I thought I had to allocate the message to the sent box and by default it goes to the inbox, this is not the case. It appears in the sent inbox anyway. Does anyone know how I can stop this?

New Topic/Question
Reply




MultiQuote




|