By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,359 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,359 IT Pros & Developers. It's quick & easy.

Mails sent from Java code going to Junk Folder in MS Outlook

P: 14
Hi Friends,

I Have written a java code to send mails to some receipients.It sends to internal mail ID's in the office. An SMTP server has been provided to me. But the problem is that the mails are being sent to Junk folder of the recepients.

1) The mail contains only plain text, it doen't have things like images or something which is treated as a SPAM or junk.

2) Since the mails are being sent to the internal mail ID's in the office, there is no point considering it to be as Junk by Outlook. (I have read in the Microsoft forums that the mails which are received from the same domain name are not considered as junk).

I am pasting the core part of the code which I am using. Please tell me if there are any problems with this.
Expand|Select|Wrap|Line Numbers
  1. public void sendMailsLogic(String to, String bcc) {
  2.         try {
  3.             Properties props = System.getProperties();
  4.             props.put("", "");
  5.             props.put("mail.smtp.auth", "true");
  6.             Session session = Session.getInstanc
  7. (props, null);
  8.             session.setDebug(true);
  10.             transport = session.getTransport("smtp");
  11.             transport.connect("", "myuserName", "myPassword");
  13.             // construct the message
  14.             Message msg = new MimeMessage(session);
  15.             msg.setFrom(new InternetAddress(from));
  17.             msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
  18.                     to.toString(), false));
  19.             msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(
  20.                     bcc.toString(), false));
  21.             msg.setSubject(subject);
  22.             msg.setText(text); // this is a function which has body of the mail.
  23.             msg.saveChanges(); 
  25.             InternetAddress[] addrs = InternetAddress.parse(from, false);
  26.             //Transport tr = session.getTransport(addrs[0]);
  27.             //tr.connect();
  29.             transport.sendMessage(msg, msg.getAllRecipients());
  30.             transport.close();
  31.             System.out.println("Message Successfully Sent");
  32.         } catch (Exception e) {
  33.             System.out.println("Exception Raised");
  34.             e.printStackTrace();
  35.         }
  36.     }
To the above function I am providing To and CC strings. It will only one person in TO and 4 persons in CC.

One more problem which I noticed is that when the mail is sent, it is verifying only the userID's of the people in TO and CC. It is not verifying the FROM userID. i.e even If i give a userID which I is not existing, it is sending the mail succesfully.

Ex. if the FROM is "abcdef" without @. even then it is sending the mail.

I know this is a very long post as I choose to explain in detail.
Please help me with this.

Thanks in advance... :)

Dec 5 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 3,112
Hi tiijnar! I moved this here from the Jobs Forum. Please post your questions in the right place in future.

Also, as you can see, I added [code] tags for you and removed the [b] tags - read our Posting Guidelines, especially the Things that are generally unacceptable.

I'll leave the answering of this question to the other Experts here, as I'm not really familiar with javamail.

Nepomuk (Moderator)
Dec 5 '08 #2

Expert 10K+
P: 11,448
Try to send an identical message manually and see if it also ends up in the junk at the recipient's side.

kind regards,

Dec 5 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.