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
- public void sendMailsLogic(String to, String bcc) {
- try {
- Properties props = System.getProperties();
- props.put("mail.smtp.host", "178.27.6.50");
- props.put("mail.smtp.auth", "true");
- Session session = Session.getInstanc
- (props, null);
- session.setDebug(true);
- transport = session.getTransport("smtp");
- transport.connect("178.27.6.50", "myuserName", "myPassword");
- // construct the message
- Message msg = new MimeMessage(session);
- msg.setFrom(new InternetAddress(from));
- msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
- to.toString(), false));
- msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(
- bcc.toString(), false));
- msg.setSubject(subject);
- msg.setText(text); // this is a function which has body of the mail.
- msg.saveChanges();
- InternetAddress[] addrs = InternetAddress.parse(from, false);
- //Transport tr = session.getTransport(addrs[0]);
- //tr.connect();
- transport.sendMessage(msg, msg.getAllRecipients());
- transport.close();
- System.out.println("Message Successfully Sent");
- } catch (Exception e) {
- System.out.println("Exception Raised");
- e.printStackTrace();
- }
- }
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... :)
Regards,
Tijnar