Javamail and Google mail SMTP server
How to send e-mails using Javamail API and SMTP server over SSL and authentication
Google mail provides a very convenient feature for spreading SPAM mails as a free SMTP server. I used it with success from my small custom SPAM mailing program, however when I tried to tune my Javamail based code, I met some problems. Finally I resolved them, so I decided to share my experience.
Prerequisites
- Make sure that you have Javamail API 1.4 or above
- Pop3 activated for gmail account
Configuration
The code below demonstrate required settings for successful usage of gmail SMTP server requiring SSL and authentication.
String ssl = "s";
Properties props = new Properties();
props.put("mail.smtp" + ssl + ".auth", "true");
props.put("mail.smtp" + ssl + ".quitwait", "false");
props.put("mail.smtp" + ssl + ".port", port); // port = 465
Session session = Session.getDefaultInstance(props, null);
// prepare message here
Transport tr = session.getTransport("smtp" + ssl);
tr.connect(host, "dmitriy@gmail.com", "mypupsy"); // 2nd - target email addr, 3rd - password
tr.sendMessage(msg, msg.getAllRecipients());
tr.close();
iPhone a serious design flaw
How to take over of it
iPhone: my thoughts
or will you buy it when you can afford it?
- no support corporative e-mail
- no disk mode, and what more important no 3rd party management programs and possibility use under Linux
- No voice dial
- No cut/paste
- No Java applications