Results 1 to 5 of 5
Thread: Hi Everyone
- 06-30-2014, 11:00 AM #1
Member
- Join Date
- Aug 2013
- Posts
- 4
- Rep Power
- 0
- 06-30-2014, 11:26 AM #2
Re: Hi Everyone
If nothing worked, then you must have a non-code problem. The internets could be down, mailserver down, proxy down. Could be lots of things. If you are sure it's the code, then "doesn't work" is not good enough. You could provide the code, error codes, stacktraces, screenshots, logfiles, you name it.
"It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013
- 06-30-2014, 11:48 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Hi Everyone
Moved out of admin only section.
Please do not ask for code as refusal often offends.
** This space for rent **
- 06-30-2014, 11:53 AM #4
Member
- Join Date
- Aug 2013
- Posts
- 4
- Rep Power
- 0
Re: Hi Everyone
Hi Surfman,
Here is the code it is working fine with normal internet but tried with network proxy no success and I'm getting exception like javax.mail.MessagingException: Could not connect to SMTP host, java.net.ConnectException: Connection refused. Is there any other way to write code for network proxy to send email as localhost please help me Thanx.
public class mail {
private static void main (string[] args) {
String[] to = {"***", "****"};
String host = "smtp.gmail.com";
String from = "****";
String pass = "****";
Properties properties = System.getProperties();
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.user", from);
properties.put("mail.smtp.password", pass);
properties.put("mail.smtp.port", "587");//587,465,25
properties.put("mail.smtp.auth", "true");
// properties.put("mail.smtp.debug", "true");
Session session = Session.getDefaultInstance(properties, null);
session.setDebug(true);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] addressTo = new InternetAddress[to.length];
for (int i = 0; i < to.length; i++) {
addressTo[i] = new InternetAddress(to[i]);
}
message.setRecipients(Message.RecipientType.TO, addressTo);
message.setSubject("Hello");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Hi All, \n\n"
+ "Please see the link bellow"
+ "\n\nKind regards,"
+ "\n Sandy");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
String filename = prop.getProperty("path") + FILENAME;
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
// Send message
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
logger.info("Sent message successfully....");
} catch (MessagingException e) {
logger.error(e);
}
}
- 06-30-2014, 12:16 PM #5
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Hi Everyone
Unsuprisingly the JavaMail FAQ has something to say about connecting through a proxy:
JavaMail API - FAQ"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
Bookmarks