lizhenghong66 / javamail-android

Automatically exported from code.google.com/p/javamail-android
0 stars 0 forks source link

Getting error while using javamail-android #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Well i had studied javamail and trying in android but while i am running the 
code i m getting error ...

05-06 10:07:45.160: ERROR/Mail app(602): 
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS 
command first. q5sm1883105pbp.65
05-06 10:07:45.160: ERROR/Mail app(602):     at 
com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
javax.mail.Transport.send0(Transport.java:189)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
javax.mail.Transport.send(Transport.java:118)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
com.livesoft.user.mail.Main$1.onClick(Main.java:49)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
android.view.View.performClick(View.java:2408)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
android.view.View$PerformClick.run(View.java:8816)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
android.os.Handler.handleCallback(Handler.java:587)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
android.os.Handler.dispatchMessage(Handler.java:92)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
android.os.Looper.loop(Looper.java:123)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
android.app.ActivityThread.main(ActivityThread.java:4627)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
java.lang.reflect.Method.invokeNative(Native Method)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
java.lang.reflect.Method.invoke(Method.java:521)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-06 10:07:45.160: ERROR/Mail app(602):     at 
dalvik.system.NativeStart.main(Native Method)

here is my code :
addImage.setOnClickListener(new OnClickListener(){

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                String host= "smtp.gmail.com";
                String to="ratnesh10.india@gmail.com";
                String from = "ratnesh10.india@gmail.com";

                Properties props= new Properties();
                props.setProperty("mail.smtp.host", host);

                Session session = Session.getDefaultInstance(props);
                try{
                    MimeMessage msg =  new MimeMessage(session);
                    msg.setFrom(new InternetAddress(from));
                    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
                    msg.setSubject("Hi..");
                    msg.setText("Test mail");
                    Transport.send(msg);
                    Toast.makeText(Main.this, "Email send succesfully", Toast.LENGTH_LONG).show();                  
                }
            catch(Exception e){
                Log.e("Mail app","there is problem in sending mail",e);
            }
            }
        });

please help me 

Original issue reported on code.google.com by ratnesh1...@gmail.com on 6 May 2011 at 4:42

GoogleCodeExporter commented 8 years ago
Ia m getting error when it reaches at line 

props.setProperty("mail.smtp.host", host);

I need help urgently .... 

Original comment by ratnesh1...@gmail.com on 6 May 2011 at 4:44

GoogleCodeExporter commented 8 years ago
You are missing some important properties for it to work, such as the SMTP 
port, authentication settings, etc, and it also lacks the authenticator for 
sending mail...

The remaining code seems to be alright.

Give a look here for a working example with Gmail:
http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javama
il-api-without-using-the-default-android-app/2033124#2033124 

Original comment by syk...@gmail.com on 5 Jul 2011 at 1:12