android studioによるアプリでメール送信のアプリを作成しております。
色々サイトを参考にしてコード書いているのですがPasswordAuthenticationの部分でエラーが出ており色々調べましたがどうしても原因が解らず悩んでおります。
【添付画像のコード赤波部分です。User name, PASSは"*"に変えています。】
何か見落としをしているのか、他に深い原因があるのか苦慮しておりますので
すいませんが、助言頂けると助かります
宜しくお願い致します。
MainActivity.java public class MainActivity extends AppCompatActivity { private Java_mail classln; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); classln = new Java_mail(); classln.mail("送信しました。"); } }
Java_mail.java import java.net.PasswordAuthentication; import java.util.Properties; import javax.mail.Address; import javax.mail.Message; import javax.mail.Multipart; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; class Java_mail { public void mail(String message) { mail t = new mail(message); t.start(); } static class mail extends Thread { private String message; mail(String message) { this.message = message; } @Override public void run(){ try { Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.transport.protocol", "smtp"); props.put("mail.smtp.ssl.trust", "*"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.connectiontimeout", "10000"); props.put("mail.smtp.timeout", "10000"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("**************", "************"); } }); Message message = new MimeMessage(session); message.setFrom(new InternetAddress("*************@gmail.com", "**********")); message.setReplyTo(new Address[]{new InternetAddress("*************@gmail.com")}); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("*************@gmail.com")); message.setSubject("メールTESTです。"); MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("TEST mail 完了。"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); message.setHeader("Content-Transfer-Encoding", "base64"); message.setContent(multipart); Transport.send(message); } catch (Exception e ) { System.out.print("例外が発生!\r\n"); e.printStackTrace(); } finally { } System.out.print("end: main\r\n"); } } }
エラーが出るならエラーメッセージを提示しましょう
すいません、ビルド時のエラーを以下抜粋致します。
2021-01-05 03:58:11.522 9575-9575/? E/ActivityThread: Failed to find provider info for com.mobisystems.msconfig.provider
2021-01-05 11:44:30.025 30669-30802/? E/ActivityThread: Failed to find provider info for com.facebook.appmanager.nekodirect
2021-01-05 15:27:52.222 12475-12533/? E/ActivityThread: Failed to find provider info for com.facebook.appmanager.nekodirect
2021-01-05 18:18:14.953 15205-15320/? E/ActivityThread: Failed to find provider info for com.facebook.appmanager.nekodirect
2021-01-05 18:18:15.355 15205-15331/? E/ActivityThread: Failed to find provider info for com.facebook.services.configuration
2021-01-05 18:18:15.357 15205-15331/? E/ActivityThread: Failed to find provider info for com.facebook.services.configuration
2021-01-05 20:20:56.402 836-1584/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'INTERFACE' not found
2021-01-05 20:20:56.402 836-1584/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'STATE' not found
2021-01-05 20:20:56.402 836-1584/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'TIME_NS' not found
2021-01-05 20:20:56.402 836-1584/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'UID' not found
2021-01-05 20:31:58.906 836-1597/? E/FrameworkListener: read() failed (Connection reset by peer)
2021-01-05 21:11:08.525 1797-1891/? E/BatteryExternalStatsWorker: no controller energy info supplied for bluetooth
2021-01-05 21:15:21.838 1797-11217/? E/WifiService: Permission violation - startScan not allowed for uid=10250, packageName=com.nttdocomo.android.dpoint, reason=java.lang.SecurityException: UID 10250 has no location permission
2021-01-05 21:21:07.238 1797-1891/? E/BatteryExternalStatsWorker: no controller energy info supplied for bluetooth
2021-01-05 21:24:25.741 1797-11662/? E/WifiService: Permission violation - getScanResults not allowed for uid=10250, packageName=com.nttdocomo.android.dpoint, reason=java.lang.SecurityException: UID 10250 has no location permission
2021-01-05 21:24:25.764 1797-2709/? E/WifiService: Permission violation - getScanResults not allowed for uid=10250, packageName=com.nttdocomo.android.dpoint, reason=java.lang.SecurityException: UID 10250 has no location permission
2021-01-05 21:31:11.344 1797-2093/? E/WifiPermissionsUtil: UID 10145 has no location permission
2021-01-05 21:31:12.251 1379-1793/? E/ActivityThread: Failed to find provider info for com.google.android.instantapps.supervisor.SupervisorArchiveProvider
2021-01-05 21:46:04.271 1797-1886/? E/AppIdleHistory: Error writing app idle file for user 0
2021-01-05 21:46:14.206 1797-2093/? E/WifiPermissionsUtil: UID 10145 has no location permission
2021-01-05 21:46:14.385 1797-1891/? E/BatteryExternalStatsWorker: no controller energy info supplied for bluetooth
2021-01-05 21:46:14.607 2615-2615/? E/VendorTagDescriptor: getTagType: Vendor descriptor id is missing!
2021-01-05 21:46:14.607 2615-2615/? E/VendorTagDescriptor: getTagType: Vendor descriptor id is missing!
2021-01-05 21:46:14.635 5512-5512/? E/ntitlementchec: Not starting debugger since process cannot load the jdwp agent.
2021-01-05 21:46:14.710 5512-5540/? E/Perf: Fail to get file list com.sonyericsson.tetherentitlementcheck
2021-01-05 21:46:14.711 5512-5540/? E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-01-05 21:46:14.711 5512-5540/? E/Perf: Fail to get file list com.sonyericsson.tetherentitlementcheck
2021-01-05 21:46:14.711 5512-5540/? E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-01-05 21:46:15.248 987-10039/? E/msm8974_platform: platform_check_backends_match: Invalid snd_device =
2021-01-05 21:46:15.251 987-10039/? E/libc: Access denied finding property "persist.spkr.cal.duration"
2021-01-05 21:46:15.264 987-10039/? E/voice: voice_is_in_call_rec_stream: input stream is NULL
2021-01-05 21:46:15.267 987-10039/? E/audio_hw_utils: send_app_type_cfg_for_device: Could not get ctl for mixer cmd - Audio Stream Capture 35 App Type Cfg
2021-01-05 21:46:15.271 987-10039/? E/ACDB-LOADER: Error: ACDB AudProc vol returned = -19
2021-01-05 21:46:15.323 987-10039/? E/ACDB-LOADER: Error: ACDB AudProc vol returned = -19
2021-01-05 21:46:15.324 987-10039/? E/ACDB-LOADER: Error: ACDB_CMD_GET_AFE_COMMON_TABLE_SIZE Returned = -19
2021-01-05 21:46:15.324 987-10039/? E/ACDB-LOADER: Error: ACDB AFE returned = -19
2021-01-05 21:46:15.324 987-10039/? E/soundtrigger: audio_extn_sound_trigger_update_stream_status: invalid input device 0x0, for event 3
2021-01-05 21:46:15.344 22936-23012/? E/MDD: DownloadProgressMonitor: Can't find file for uri: android://com.google.android.googlequicksearchbox/files/sharedminusonemodule/shared/SharedMinusOneData.pb.tmp
2021-01-05 21:46:15.463 987-10039/? E/msm8974_platform: platform_set_channel_map: Could not set ctl, error:-22 ch_count:2
2021-01-05 21:46:16.920 5709-28438/? E/BtGatt.ContextMap: Context not found for info com.android.bluetooth.gatt.GattService$PendingIntentInfo@f45ce56
2021-01-05 21:46:18.588 5615-5615/? E/d.configupdate: Not starting debugger since process cannot load the jdwp agent.
2021-01-05 21:46:18.747 5615-5664/? E/Perf: Fail to get file list com.google.android.configupdater
2021-01-05 21:46:18.747 5615-5664/? E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-01-05 21:46:18.748 5615-5664/? E/Perf: Fail to get file list com.google.android.configupdater
2021-01-05 21:46:18.748 5615-5664/? E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-01-05 21:46:18.750 987-1556/? E/soundtrigger: audio_extn_sound_trigger_update_stream_status: invalid input device 0x0, for event 2
2021-01-05 21:46:19.153 1041-1072/? E/ANDR-PERF-UTIL: Failed to read /proc/sys/kernel/sched_busy_hyst_ns
2021-01-05 21:46:19.153 1041-1072/? E/ANDR-PERF-OPTSHANDLER: Failed to read /proc/sys/kernel/sched_busy_hyst_ns
2021-01-05 21:46:19.153 1041-1072/? E/ANDR-PERF-RESOURCEQS: Failed to apply optimization [1, 2]
2021-01-05 21:46:19.186 2048-2050/? E/ANDR-IOP: io prefetch is disabled
2021-01-05 21:46:19.780 1124-1124/? E/Layer: [Surface(name=AppWindowToken{cf0bb7d token=Token{6e25dd4 ActivityRecord{61c4727 u0 com.coconala.android.portal/.old.presentation.activity.FromPushWithOpenActivity t95}}})/@0x61c406e - animation-leash#0] No local sync point found
2021-01-05 21:46:20.958 5920-5920/? E/ocessService0:: Not starting debugger since process cannot load the jdwp agent.
2021-01-05 21:46:22.829 5082-5440/? E/System: Ignoring attempt to set property "java.net.preferIPv6Addresses" to value "false".
2021-01-05 21:46:24.990 1366-1443/? E/statsd: Found dropped events: 1 error -19 last atom tag 83 from uid 10015
2021-01-05 21:47:14.108 2289-2434/? E/WifiScanner: listener cannot be found
回答2件
あなたの回答
tips
プレビュー