[java-l] SMTP server Authentication

Question from Prabhu on Apr 30 at 2:20 AM
Hi,

I am using the below code to send email. Without providing the password i am able to send the email using SMTP server. In the from field if i provide the wrong email ID it is send the email. Why it is happening like that..

Code:

public void CreateEmail {
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpserver);
properties.put("mail.smtp.port", smtpserverport);
Session session = Session.getDefaultInstance(properties, null);

try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(From));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(To));
//message.setRecipient(Message.RecipientType.CC, new InternetAddress(CC));
//message.setRecipient(Message.RecipientType.BCC, new InternetAddress(Bcc));
message.setSubject(Subject);
message.setSentDate(new Date());

// Set the email message text.

MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText(bodyText);

// Set the email attachment file

MimeBodyPart attachmentPart = new MimeBodyPart();

FileDataSource fileDataSource = new FileDataSource(filename) {
@Override
public String getContentType() {
return "application/octet-stream";
}
};
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(fileDataSource.getName( ));
Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messagePart);
multipart.addBodyPart(attachmentPart);

message.setContent(multipart);

Transport.send(message);
System.out.println("Message Sent");

} catch (MessagingException e) {
e.printStackTrace();
}
}
 
Reply to this email to post your response.
 
__.____._
Manage Settings | Unsubscribe | Create FAQ | Send Feedback
  
Copyright © 2012 Toolbox.com and message author.
Toolbox.com 4343 N. Scottsdale Road Suite 280, Scottsdale, AZ 85251
Prabhu  
 
View this online
Ask a new question
 
In the Spotlight
Have a Java Question? Ask Your Peers at Toolbox for IT

_.____.__

No comments:

Post a Comment