0

I'm trying to send an email[NO INTENT] from my application , but it does not send. Can maybe anyone tell me what wrong there is no error in LOGCAT.

final Button send = (Button) this.findViewById(R.id.btnSend); 
        send.setOnClickListener(new View.OnClickListener() { 

            public void onClick(View v) {         
           try 
         {    
            javamail sender = new javamail("MY EMAIL", "My Password" ); 
            sender.sendMail("HI",    
                    "I'm trying Androin Email :)",    
                    "Person I sent to",    
                    "djkgotsod@gmail.com");    
            Log.d("send", "Owk");
        } catch (Exception e) {    
            Log.e("SendMail", e.getMessage(), e);    
        }  

    } 
}); 
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
user1430923
  • 63
  • 3
  • 10
  • One thing that is wrong is that you are doing network I/O on the main application thread. At best, this is dangerous; at worst, Android will crash your app. Please move your network I/O to a background thread. – CommonsWare Jun 03 '12 at 12:14
  • that what i saw in the example I was using.. – user1430923 Jun 03 '12 at 12:22
  • @CommonsWare i have used example you have given but its not working for me.. does it needs any smtp or any other setting?? please help me.. Thanks in advance... – Mahaveer Muttha Jan 17 '13 at 15:50

2 Answers2

2

What I do, is send the email to a php script using HTTP POST. Then my server sends the actual email using php's mail(). That way, you bypass a minefield of problems eg some carriers block port 25.

servermanfail
  • 2,532
  • 20
  • 21
0

check out this post, It uses JavaMail API with Gmail authenticator. Note, You must type in a valid gmail user and password Hope this helps.

Community
  • 1
  • 1
Li3ro
  • 1,837
  • 2
  • 27
  • 35
  • That what I used but...still i dont get tha results...my gmail is valid and password – user1430923 Jun 03 '12 at 12:20
  • void com.proapps.eng.android.client.GMailSender.sendMail(String subject, String body, String sender, String recipients) throws Exception try this: sender.sendMail("subject","body","The Sender Email!!!" , "the Recepient Email like djkgotsod@gmail.com"); – Li3ro Jun 03 '12 at 16:35
  • Can you please paste your exception.. try wrap the whole thing with try catch maybe – Li3ro Jun 03 '12 at 16:37
  • what do you mean because everything is on try catch – user1430923 Jun 04 '12 at 06:44
  • Have you tried,as said before, to change the sender email in sender.sendMail method? – Li3ro Jun 04 '12 at 11:17
  • cant you post that method u talking about – user1430923 Jun 04 '12 at 14:15
  • There u go.. this works perfect for me: try {GMailSender sender = new GMailSender(cntx.getString(R.string.from_mail), cntx.getString(R.string.from_mail_pass)); sender.sendMail("Mail Sent from Customer "+name_text.getText().toString(), free_text.getText().toString() + "\n\n\nPhone Number: "+ phone_text.getText().toString()+ "\nDate: "+ _date + "\nTime: " + _time, cntx .getString(R.string.from_mail), cntx .getString(R.string.customer_mail));} catch (Exception e) {Log.e("SendMail", e.getMessage(), e);} – Li3ro Jun 05 '12 at 05:36