Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

the mails are goes to Badmail folder of the host

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, i am using java mail API to Send mails , my code is executed correctly but, all mails are goes to badmail folder of the host
and my code is ....

package com;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
* @author gaucho
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class SendMailUsingAuthentication {

private static final String SMTP_HOST_NAME = "192.168.2.33";
private static final String SMTP_AUTH_USER = "chiranjeevi@theikos.com";
private static final String SMTP_AUTH_PWD = "Password1";
private static final String emailMsgTxt = "Please visit my project at ";
private static final String emailSubjectTxt = "Order Confirmation Subject";
private static final String emailFromAddress = "chiranjeevi@theikos.com";

// Add List of Email address to who email needs to be sent to
private static final String[] emailList = { "chiranjeevi@theikos.com"};

public static void main(String args[]) throws Exception {
SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
smtpMailSender.postMail(emailList, emailSubjectTxt, emailMsgTxt,
emailFromAddress);
System.out.println("Sucessfully Sent mail to All Users");
}

public void postMail(String recipients[], String subject, String message,
String from) throws MessagingException {
boolean debug = false;
java.security.Security
.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

//Set the host smtp address
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug","true");

Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);

session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo = new InternetAddress(recipients);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}

/**
* SimpleAuthenticator is used to do simple authentication when the SMTP
* server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator {

public PasswordAuthentication getPasswordAuthentication() {
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}
}


the out put is

[nobr]DEBUG: JavaMail version 1.3.3
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.5.0_04\lib\javamail.providers (The system cannot find the file specified)
DEBUG: URL jar:file:/C:/EmailAgent60/lib/imap.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/C:/EmailAgent60/lib/imap.jar!/META-INF/javamail.providers
DEBUG: URL jar:file:/C:/EmailAgent60/lib/pop3.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/C:/EmailAgent60/lib/pop3.jar!/META-INF/javamail.providers
DEBUG: URL jar:file:/C:/EmailAgent60/lib/smtp.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/C:/EmailAgent60/lib/smtp.jar!/META-INF/javamail.providers
DEBUG: not loading resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsy stems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsy stems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc]}
DEBUG: not loading resource: /META-INF/javamail.default.address.map
DEBUG: URL jar:file:/C:/EmailAgent60/lib/smtp.jar!/META-INF/javamail.address.map
DEBUG: successfully loaded resource: jar:file:/C:/EmailAgent60/lib/smtp.jar!/META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.5.0_04\lib\javamail.address.map (The system cannot find the file specified)
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "192.168.2.33", port 25, isSSL false
220 Dunagiri Microsoft ESMTP MAIL Service, Version: 5.0.2195.6713 ready at Wed, 12 Jul 2006 11:40:07 +0530
DEBUG SMTP: connected to host "192.168.2.33", port: 25

EHLO manas
250-Dunagiri Hello [192.168.2.64]
250-TURN
250-ATRN
250-SIZE 2097152
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250 OK
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "ATRN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "2097152"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8bitmime", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "OK", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<chiranjeevi@theikos.com>
250 2.1.0 chiranjeevi@theikos.com....Sender OK
RCPT TO:<chiranjeevi@theikos.com>
250 2.1.5 chiranjeevi@theikos.com
DEBUG SMTP: Verified Addresses
DEBUG SMTP: chiranjeevi@theikos.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Message-ID: <29509536.01152684496937.JavaMail.chiranjeevi@manas>
Date: Wed, 12 Jul 2006 11:38:16 +0530 (GMT+05:30)
From: chiranjeevi@theikos.com
To: chiranjeevi@theikos.com
Subject: Test E-Mail through Java
Cc: chiranjeevi@theikos.com
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is a test of sending a plain text e-mail through Java.
Here is line 2.
.
250 2.6.0 <29509536.01152684496937.JavaMail.chiranjeevi@manas> Queued mail for delivery
DEBUG SMTP: use8bit false
MAIL FROM:<chiranjeevi@theikos.com>
250 2.1.0 chiranjeevi@theikos.com....Sender OK
RCPT TO:<chiranjeevi@theikos.com>
250 2.1.5 chiranjeevi@theikos.com
DEBUG SMTP: Verified Addresses
DEBUG SMTP: chiranjeevi@theikos.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Message-ID: <15277917.11152684497046.JavaMail.chiranjeevi@manas>
Date: Wed, 12 Jul 2006 11:38:16 +0530 (GMT+05:30)
From: chiranjeevi@theikos.com
To: chiranjeevi@theikos.com
Subject: Test E-Mail through Java
Cc: chiranjeevi@theikos.com
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_19690856.1152684497031"

------=_Part_0_19690856.1152684497031
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is part one of a test multipart e-mail.
------=_Part_0_19690856.1152684497031
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is the second part
------=_Part_0_19690856.1152684497031--

.
250 2.6.0 <15277917.11152684497046.JavaMail.chiranjeevi@manas> Queued mail for delivery
DEBUG SMTP: use8bit false
MAIL FROM:<chiranjeevi@theikos.com>
250 2.1.0 chiranjeevi@theikos.com....Sender OK
RCPT TO:<chiranjeevi@theikos.com>
250 2.1.5 chiranjeevi@theikos.com
DEBUG SMTP: Verified Addresses
DEBUG SMTP: chiranjeevi@theikos.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Message-ID: <11587215.21152684497093.JavaMail.chiranjeevi@manas>
Date: Wed, 12 Jul 2006 11:38:16 +0530 (GMT+05:30)
From: chiranjeevi@theikos.com
To: chiranjeevi@theikos.com
Subject: Test E-Mail through Java
Cc: chiranjeevi@theikos.com
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_19690856.1152684497031"

------=_Part_0_19690856.1152684497031
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is part one of a test multipart e-mail.
------=_Part_0_19690856.1152684497031
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is the second part
------=_Part_0_19690856.1152684497031--

.
250 2.6.0 <11587215.21152684497093.JavaMail.chiranjeevi@manas> Queued mail for delivery
DEBUG SMTP: use8bit false
MAIL FROM:<chiranjeevi@theikos.com>
250 2.1.0 chiranjeevi@theikos.com....Sender OK
RCPT TO:<chiranjeevi@theikos.com>
250 2.1.5 chiranjeevi@theikos.com
DEBUG SMTP: Verified Addresses
DEBUG SMTP: chiranjeevi@theikos.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Message-ID: <10807107.31152684497156.JavaMail.chiranjeevi@manas>
Date: Wed, 12 Jul 2006 11:38:16 +0530 (GMT+05:30)
From: chiranjeevi@theikos.com
To: chiranjeevi@theikos.com
Subject: Test E-Mail through Java
Cc: chiranjeevi@theikos.com
MIME-Version: 1.0
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html><head><title>Test E-Mail through Java</title></head><body><h1>Test E-Mail through Java</h1>
This is a test of sending an HTML e-mail through Java.</body></html>
.
250 2.6.0 <10807107.31152684497156.JavaMail.chiranjeevi@manas> Queued mail for delivery
QUIT
[/nobr]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic