dcsimg
Problems While sending mails using java mail
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ditty_Dave
Posted On:   Monday, November 28, 2005 11:43 AM

Why am i getting SMTPSendFailedException,invalid recipient inspite of having the code right??? heres my code import javax.mail.*; import javax.mail.internet.*; import java.util.*; import javax.mail.Authenticator; import javax.mail.PasswordAuthentication; public class SendEmail { public static void main(String[] args) { System.out.println(args.length); if (args.length != 6) { System.out.println("usage: sendmessage "); System.exit(1);System.out.println("jj"+args.length); } SendEmail m=new SendEmail(); m.SendMessage(args[0],args[1], args[2], args[3],   More>>

Why am i getting SMTPSendFailedException,invalid recipient inspite of having the code right???


heres my code



import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;



public class SendEmail
{
public static void main(String[] args)
{
System.out.println(args.length);
if (args.length != 6)
{
System.out.println("usage: sendmessage ");
System.exit(1);System.out.println("jj"+args.length);
}


SendEmail m=new SendEmail();

m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);


}

public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
{
boolean debug = false; // change to get more
String msgText2 = "multipart message";
boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
// set the host
Properties props = new Properties();



props.put("mail.smtp.host",smtphost);

props.put("mail.smtp.starttls.enable","true");

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.sendpartial", "true");



Authenticator loAuthenticator = new SMTPAuthenticator();
System.out.println("f");

// create some properties and get the default Session

Session session = Session.getDefaultInstance(props, loAuthenticator );
session.setDebug(debug);
System.out.println("ff");

try
{
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(emailfrom);
msg.setFrom(from);
InternetAddress[] address =
{

new InternetAddress(emailto)

};
System.out.println("fv");

msg.setRecipients(Message.RecipientType.TO, address);
System.out.println("fc");
msg.setSubject(msgSubject);
System.out.println("fvf");
if(!sendmultipart)
{
// send a plain text message
msg.setContent(msgText, "text/plain");
System.out.println("fif");
}
else

{
System.out.println("felsd");
// send a multipart message// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
}
Transport transport = session.getTransport("smtp");
System.out.println("ft");
transport.connect(smtphost,"nisha.mahida@gmail.com","xyz");
msg.saveChanges();
System.out.println("fconn");
transport.sendMessage(msg,msg.getAllRecipients());
System.out.println("fsend");
transport.close();


System.out.println("fsend");

}
catch(MessagingException mex)
{
mex.printStackTrace();
}
return "Email sent to " + emailto;

}

}

class SMTPAuthenticator extends Authenticator
{

public PasswordAuthentication getPasswordAuthentication()
{
String username = "mahida_nisha@yahoo.co.in";
String password = "xyz";
return new PasswordAuthentication(username, password);
}

}

   <<Less

Re: Problems While sending mails using java mail

Posted By:   Ditty_Dave  
Posted On:   Wednesday, November 30, 2005 01:32 AM

Yes Sir i have tried printing the recipients address.. Its Getting printed..
Also the isConnected() property returning true..
The code sometimes runs..but the same code doesnt run sometime..
i always get the same SMTPSendfailedException:550invalid recipient and exception at transport.send()..
is there a firewall problem or some other problem????
please help me in solving this problem.
thanks..

Re: Problems While sending mails using java mail

Posted By:   WarnerJan_Veldhuis  
Posted On:   Tuesday, November 29, 2005 04:56 AM

I haven't seen your code, but the message "invalid recipient" shows that the mail contains an invalid recepient. Did you debug the code and System.out.println-ed the emailaddress. If no, do that first. And if yes, what did it look like??
About | Sitemap | Contact