2012-03-31 236 views
0

Sending Email in Android using JavaMail API without using the default/built-in app在机器人发送电子邮件“发送不起作用”

我想根据上面的链接,所以我创建了三个班,使电子邮件应用程序为我的Android,做了一个简单的布局,但我可以”让它工作?当我在模拟器中启动应用程序并且布局出现时,我按下发送没有响应。我怀疑问题在于“发送”。有小费吗?

我也在清单中添加了。使用权限android:name =“android.permission.INTERNET”

做了一个简单的布局...每次我按发送按钮,它不发送,只打印出“buttonbutton”!

package gaia.feedback.com; 

import android.app.Activity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 

public class GaiaFeedbackActivity extends Activity { 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

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

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       try { 
        GmailSender sender = new GmailSender("[email protected]", "password"); 
        sender.sendMail("This is Subject", 
          "This is Body", 
          "[email protected]", 
          "[email protected]"); 
        System.out.println("buttonbutton"); 

       } catch (Exception e) { 
        Log.e("SendMail", e.getMessage(), e); 
        System.out.println("coolcool"); 
       } 

      } 
     }); 

    } 
} 
+0

支票设备?... – 2012-03-31 18:29:49

+0

希望你有包括3个库完美。 – Bhavin 2012-03-31 18:30:41

+0

@萨米尔尚未完成它!但是,如果我在模拟器或设备上运行,它会产生什么影响吗? – 2012-03-31 18:32:23

回答

1

如果您需要发送唯一的邮件,你可以使用下面的线

Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_VIEW); 
intent.setData(Uri.parse("mailto:")); 
startActivity(Intent.createChooser(intent, "Send via...")); 
1
If you want to add subject and body then you can use the below method 

private void sendMail(String subject,String body){ 
String mail = "mailto:[email protected]&subject="+subject+"&body="+body; 
Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_VIEW); 
intent.setData(Uri.parse(mail)); 
startActivity(Intent.createChooser(intent, "Send via...")); 
}