File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
Greenhorn

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


String from = "test@gmail.com";
String to = "test@abc.com";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
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("mail.smtp.host", 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.setSubject("ONLINE SHOPPING DETAILS ");
msg.setSentDate(new Date());




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


//Send the message
Transport.send(msg);
}

catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
Rangana Minesh wrote:
msg.setSubject("ONLINE SHOPPING DETAILS ");
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
Greenhorn

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaMail e-mail goes to Junk E-mail