Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

SMTP from Java and Gmail

Avatar of a1programmer
a1programmerFlag for United States of America asked on
JavaJava EE
11 Comments1 Solution750 ViewsLast Modified:
I'm working on a Java POP3 / SMTP client for sending/receiving emails using which will be integrated with a custom socket server.

The problem is that when I send the email from my PC, the emails don't get received by the recipient, because the destination email thinks it's spoofed.  

I figured that if I sent an email from GMail / SMTP, while authenticated, etc, that I would get the same result as if I logged into the GMail web interface... But, this is what the message looks like.

Return-Path: <verify@domain_dot_com>
Received: from Desktop (ip-yyy-zzz-xx.dhcp.ispdomain.com [ip.yyy.zzz.xx])
        by mx.google.com with ESMTPS id 21sm74440iwn.11.2010.02.18.13.05.13
        (version=SSLv3 cipher=RC4-MD5);
        Thu, 18 Feb 2010 13:05:14 -0800 (PST)
Date: Thu, 18 Feb 2010 16:05:05 -0500 (EST)
From: verify@domain_dot_com
To: target@target_dot_net
Message-ID: <16627215.0.166211352034541.JavaMail.UserName@Desktop>
Subject: Device Verified
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

message body


Here's a section of the code: (See snippet)



sendEmail(String from,String to, String subject, String body) throws MessagingException {
       
            String host = "smtp.gmail.com";
        
            Properties props = new Properties();
            
            props.put("mail.smtps.auth", "true");
            props.put("mail.smtp.host", host);
            props.put("mail.smtp.port", "465");
            
            Session sendSession = Session.getInstance(props);
            sendSession.setDebug(true);
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
            
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject(subject);
            msg.setSentDate(new Date());

//          // Set message content
            msg.setText(body);
            
            Transport t = sendSession.getTransport("smtps");
            try {
                t.connect(host, username, password);
                t.sendMessage(msg, msg.getAllRecipients());
            } finally {
                t.close();
            }
        
            System.out.println("Email Sent.");
     
    }
ASKER CERTIFIED SOLUTION
Avatar of a1programmer
a1programmerFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answers