Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sending mail through a proxy client

843830Mar 29 2006 — edited Apr 6 2006
I have the following code to send mail through my Gmail ac:

package com.apna.beans;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.activation.DataHandler ;

public class SMail{

public static void main(String[]a){
System.getProperties().put("proxySet","true");
System.getProperties().put("http.proxyPort","25");
System.getProperties().put("http.proxyHost","192.168.0.1");

Properties props = System.getProperties ();

String msg = "";

// Get system properties
final String username = "vedijitendra";
final String password = "***************";
props.put("mail.smtp.host", "192.168.0.1");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.user", username);
props.put("mail.smtp.auth","true"); // this is imp for authorisation.
props.put("mail.host", "192.168.0.1");
props.put("mail.debug", "true");
props.put("mail.store.protocol", "pop3");
props.put("mail.transport.protocol", "smtp");

try{
//here the authorisation takes place using an Anonymous class.
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator (){
protected
javax.mail.PasswordAuthentication
getPasswordAuthentication() {
return new
javax.mail.PasswordAuthentication(username,
password);
}});

// Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("vedijitendra@gmail.com"));
message.addRecipient( Message.RecipientType.TO, new
InternetAddress("vedijitendra@gmail.com"));
message.setSubject("Test");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("mailMessage");
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
//multipart.addBodyPart(messageBodyPart);
// // Part two is attachment // // Create second body part
//messageBodyPart = new MimeBodyPart();
// Get the attachment
//DataSource source = new FileDataSource(attachment);
// Set the data handler to the attachment
//messageBodyPart.setDataHandler (new DataHandler(source));
// Set the filename
//messageBodyPart.setFileName(attachment);
// Add part two
//multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent("text", "text/html");
// Send the message
Transport.send(message);
msg = "The mail has been sent.";
} catch(Exception e){
System.out.println ("---------Exception new send-------"+e);
msg = "The mail has not been sent.";
}
}
}

I get the following exception:

com.sun.mail.smtp.SMTPSendFailedException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1353)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:924)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:553)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)

I am running the code on a proxy client.

Can anyone pls help?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 4 2006
Added on Mar 29 2006
7 comments
730 views