Skip to main content

Problems with sending mail by javaMail with connection by proxy.

No replies
kamilbek
Offline
Joined: 2010-03-14

I want to sand mail by javaMail, from computer with connection to Inthernet with proxy (need login and passsword). There are DNS in connection (window's) to LAN.
When I try to send mail, exception occured: javax.mail.MessagingException: Connection refused: connect; nested exception is: java.net.ConnectException: Connection refused: connect
But NetBeans, for example, connect seccessfully.
My code is:

Properties props = new Properties();
props.setProperty("mail.smtp.host", "smtp.mail.ru");
props.setProperty("mail.smtp.port", "2525");
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.user", "mymail");
props.setProperty("mail.password", "password");

Session mailSession = Session.getInstance(props, null);
try
{
Transport transport = mailSession.getTransport("smtp");

MimeMessage message = new MimeMessage(mailSession);
message.setHeader("X-Priority", "1");
message.setSubject("Message");
message.setContent(messageText, "text/plain; charset=UTF-8");
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(recepient));
message.setFrom(new InternetAddress("mymail@mail.ru"));
transport.connect("mymail","password");
transport.sendMessage(message,
message.getRecipients(Message.RecipientType.TO));
transport.close();
}
catch(Exception ex)
{
System.out.print(ex);
}

In Java control panel(Java Control Panel -> Network Settings) I check checkbox "Use Browser settings"
And try to add code before sendng:
System.setProperty("java.net.useSystemProxies", "true");
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyPort", "192.168.1.1");
System.setProperty("http.proxyUsername", "username");
System.setProperty("http.proxyPassword", "password");
System.setProperty("http.proxyAuthType", "basic");//System.setProperty("http.proxyAuthType", "digit");

But it don't work.

Message was edited by: kamilbek