I work on my office network which uses HTTPS proxy that requires authentication. I'm in need of an application that will send email through a gmail account. I have some basic knowledge in JAVA. Please help me by answering whether is it possible to send SMTP email behind HTTPS proxy that requires authentication? If it is possible please suggest me with some java code.
I can also implement the same in any other programming language, if the process is going to be easy than in java. Please help me with this.
Thanks in advance.
I have tried the following code which I got from a similar thread,
public static void main(String[] args) {
final String username = "username@gmail.com";
final String password = "password";
System.setProperty("http.proxyHost", "103.27.171.32");
System.setProperty("http.proxyPort", "80");
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("xxxx@gmail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
`
But I'm getting the following error,
java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;