Java Mail: won't sent an email -
i have code worked fine earlier on, won't sent emails. there wrong in code?
there error says program couldn't connect smtp server of google.
here's code:
import java.util.*; import javax.mail.*; import javax.mail.internet.*; public class mailing { public mailing() { } public void getmail(string warning,string subject) { final string username = "wim81.vangeyt@gmail.com"; final string password = "minidisc"; properties props = new properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.startssl.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "465"); 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("wim81.vangeyt@gmail.com")); message.setrecipients(message.recipienttype.to, internetaddress.parse("wimvangeyt@outlook.com")); message.setsubject(subject); message.settext(warning); transport.send(message); system.out.println("done"); } catch (messagingexception e) { throw new runtimeexception(e); } } public static void main(string[] args) { mailing mailing = new mailing(); mailing.getmail("test", "test mail"); } }
may enable settings in gmail account have given in code email can sent. you.
Comments
Post a Comment