我正在开发一个应用程序。我在其中从我的应用程序发送电子邮件。我正在使用代码将邮件发送为:
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { too });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, sub);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(emailIntent, "Choose Email Clients..."));
通过使用此代码,我可以发送电子邮件。因为默认邮件编辑器是可访问的。
我的问题是:用户无法在默认作曲家(正文、主题和字段)中编辑的应用程序需要。但是作曲家字段是可编辑的。那么如何使可编辑为假。
我作为邮件正文、主题和发送给谁的全部数据都来自数据库。用户无权更改或修改它。
我在谷歌上搜索并得到了一些不使用意图发送电子邮件的代码,我觉得这很复杂。链接在这里
按照链接中给出的步骤后,我得到了错误,如下所示:
03-07 18:06:05.750: D/dalvikvm(12734): GC_CONCURRENT freed 303K, 53% free 2699K/5639K, external 141K/518K, paused 3ms+2ms
03-07 18:06:26.430: E/MailApp(12734): Could not send email
03-07 18:06:26.430: E/MailApp(12734): javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
03-07 18:06:26.430: E/MailApp(12734): nested exception is:
03-07 18:06:26.430: E/MailApp(12734): java.net.SocketException: Host is unresolved: smtp.gmail.com
03-07 18:06:26.430: E/MailApp(12734): at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
03-07 18:06:26.430: E/MailApp(12734): at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
03-07 18:06:26.430: E/MailApp(12734): at javax.mail.Service.connect(Service.java:310)
03-07 18:06:26.430: E/MailApp(12734): at javax.mail.Service.connect(Service.java:169)
03-07 18:06:26.430: E/MailApp(12734): at javax.mail.Service.connect(Service.java:118)
03-07 18:06:26.430: E/MailApp(12734): at javax.mail.Transport.send0(Transport.java:188)
03-07 18:06:26.430: E/MailApp(12734): at javax.mail.Transport.send(Transport.java:118)
03-07 18:06:26.430: E/MailApp(12734): at com.ocs.sendmailcustom.Mail.send(Mail.java:104)
03-07 18:06:26.430: E/MailApp(12734): at com.ocs.sendmailcustom.Main$1.onClick(Main.java:31)
03-07 18:06:26.430: E/MailApp(12734): at android.view.View.performClick(View.java:2538)
03-07 18:06:26.430: E/MailApp(12734): at android.view.View$PerformClick.run(View.java:9152)
03-07 18:06:26.430: E/MailApp(12734): at android.os.Handler.handleCallback(Handler.java:587)
03-07 18:06:26.430: E/MailApp(12734): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 18:06:26.430: E/MailApp(12734): at android.os.Looper.loop(Looper.java:123)
03-07 18:06:26.430: E/MailApp(12734): at android.app.ActivityThread.main(ActivityThread.java:3691)
03-07 18:06:26.430: E/MailApp(12734): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 18:06:26.430: E/MailApp(12734): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 18:06:26.430: E/MailApp(12734): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-07 18:06:26.430: E/MailApp(12734): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-07 18:06:26.430: E/MailApp(12734): at dalvik.system.NativeStart.main(Native Method)
03-07 18:06:26.430: E/MailApp(12734): Caused by: java.net.SocketException: Host is unresolved: smtp.gmail.com
03-07 18:06:26.430: E/MailApp(12734): at java.net.Socket.connect(Socket.java:985)
03-07 18:06:26.430: E/MailApp(12734): at java.net.Socket.connect(Socket.java:945)
03-07 18:06:26.430: E/MailApp(12734): at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
03-07 18:06:26.430: E/MailApp(12734): at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:163)
03-07 18:06:26.430: E/MailApp(12734): at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
03-07 18:06:26.430: E/MailApp(12734): ... 19 more
在设备上以 SAMSUNG Galaxy s2 运行应用程序时出现此错误。
但它在 LG 擎天柱 E400 上成功运行。
那么我应该怎么做或按照步骤来完成任务。或者有没有办法无意识地发送邮件。