Re: DEBUG SMTP RCVD: 354 Enter mail, end with "." on a line by itself
- From: kapil.varshney@xxxxxx
- Date: 30 May 2006 05:58:48 -0700
here is my source code-----------------
/*
Some SMTP servers require a username and password authentication before
you
can use their Server for Sending mail. This is most common with couple
of ISP's who provide SMTP Address to Send Mail.
This Program gives any example on how to do SMTP Authentication
(User and Password verification)
This is a free source code and is provided as it is without any
warranties and
it can be used in any your code for free.
*/
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
/*
To use this program, change values for the following three constants,
SMTP_HOST_NAME -- Has your SMTP Host Name
SMTP_AUTH_USER -- Has your SMTP Authentication UserName
SMTP_AUTH_PWD -- Has your SMTP Authentication Password
Next change values for fields
emailMsgTxt -- Message Text for the Email
emailSubjectTxt -- Subject for email
emailFromAddress -- Email Address whose name will appears as "from"
address
Next change value for "emailList".
This String array has List of all Email Addresses to Email Email
needs to be sent to.
Next to run the program, execute it as follows,
SendMailUsingAuthentication authProg = new
SendMailUsingAuthentication();
*/
public class SendMailUsingAuthentication
{
private static final String SMTP_HOST_NAME = "10.220.43.82";
private static final String SMTP_AUTH_USER = "bea";
private static final String SMTP_AUTH_PWD = "bea";
private static final String emailMsgTxt = "\nmanish \r\n.\r\n.";
private static final String emailSubjectTxt = "Order Confirmation
Subject1";
private static final String emailFromAddress =
"tushar.mittal@xxxxxx";
// Add List of Email address to who email needs to be sent to
private static final String[] emailList = {"kapil.varshney@xxxxxx"};
public static void main(String args[])
{
try{
SendMailUsingAuthentication smtpMailSender = new
SendMailUsingAuthentication();
smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt,
emailFromAddress);
System.out.println("Sucessfully Sent mail to All Users");
}catch(Exception e){
System.out.println("Exception thrown--------------------");
e.printStackTrace();
}
}
public void postMail( String recipients[ ], String subject,
String message , String from) throws
MessagingException
{
boolean debug = true;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
//Authenticator auth=new SMTPAuthenticator( "bea", "bea" );
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
System.out.println("got 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[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
System.out.println("before setting subject");
msg.setSubject(subject);
System.out.println("before setting contect");
msg.setContent(message, "text/plain");
System.out.println("after setting contect");
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);
}
}
}
.
- References:
- DEBUG SMTP RCVD: 354 Enter mail, end with "." on a line by itself
- From: kapil . varshney
- DEBUG SMTP RCVD: 354 Enter mail, end with "." on a line by itself
- Prev by Date: DEBUG SMTP RCVD: 354 Enter mail, end with "." on a line by itself
- Next by Date: Re: DEBUG SMTP RCVD: 354 Enter mail, end with "." on a line by itself
- Previous by thread: DEBUG SMTP RCVD: 354 Enter mail, end with "." on a line by itself
- Next by thread: Re: DEBUG SMTP RCVD: 354 Enter mail, end with "." on a line by itself
- Index(es):
Relevant Pages
|