my dog learned polymorphism*
The moose likes Other JSE/JEE APIs and the fly likes JavaMail e-mail goes to Junk E-mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail e-mail goes to Junk E-mail" Watch "JavaMail e-mail goes to Junk E-mail" New topic

JavaMail e-mail goes to Junk E-mail

Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Hi All,
E-mail from my application directly goes to Junk e-mail. I am using Microsoft Outlook which is connected to Microsoft exchange. Dumb solution here is mark the first e-mail as Not Spam and then onwards it directly goes to Inbox.

Can anyone here know how to rectify this problem.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

That means that the server which receives the e-mail thinks it looks like spam. The solution, then, would be to try to make your e-mail look less like spam.

It's hard to say how you might do that when we don't know anything about how you're formatting or sending your e-mails. So all I can suggest at this point is that you should research how anti-spam products work and act accordingly.
Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Thanks for your reply.
Rangana Minesh

Joined: May 16, 2009
Posts: 4
Try With this Code

String from = "";
String to = "";
String host = "your host ";

// Create properties, get Session
Properties props = new Properties();

// If using static Transport.send(),
// need to specify which host to send it to
props.put("", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
Session session = Session.getInstance(props);

try {
// Instantiatee a message
Message msg = new MimeMessage(session);

//Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSentDate(new Date());

msg.setContent("<h1> Online Shopping Details</h1>", "text/html");

//Send the message

catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41114
Rangana Minesh wrote:
msg.setContent("<h1> Online Shopping Details</h1>", "text/html");

Having an all-uppercase subject, using HTML, and repeating the words "online shopping" are all excellent ways to increase the likelihood of an email being classified as spam.

Ping & DNS - my free Android networking tools app
Vivek Alampally
Ranch Hand

Joined: Jul 10, 2008
Posts: 67
Thanks Rangana for your code. Sorry for being this late to respond. The problem was solved before itself. I did do minor modifications to my code. And now my e-mail goes direclty to inbox.

But can any body tell me, what all should I require to send e mail to person B from a Java program,
Answer I guess would be,

1. SMTP server name
2. User id & password of smtp server
3. Reciepient mail address

I am asking this question because I am still not sure what an SMTP server does. I know when I google about it there's a lot of theory involved with it. But can anybody tell
the process involved in it in three - four lines?
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Three or four lines? Don't short-change yourself. If you're going to be sending e-mail then take some time to understand the process properly. One of the reasons that 90% of the messages sent by e-mail these days are spam is, there's way too many people who set up servers without understanding what they do.

Here's the Wikipedia article: Simple Mail Transfer Protocol.
Mahendra Hegde

Joined: Dec 23, 2011
Posts: 1
Hi Vivek Alampally,
Please can you tell me what changes you have done to fix the issue in your code.
Even my application mail is going to junk mail in some mail id's (mail is having image)
subject: JavaMail e-mail goes to Junk E-mail
Similar Threads
Only fun forwards for fun ...
Java code for giving write permission to group(775)
Chain Email
Want a Book of K&B for preparation of SCJP1.5
Want a book of K&B for SCJP1.5