pavloasto
Dla Gmaila wykorzystuje takie ustawienia i działa:
props.put("mail.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.quitwait", "false");
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
Nie, dalej nic. Nie pomogło mi :/
Kod:
Spoiler
public class MainActivity extends Activity {
Session session = null;
ProgressDialog pdialog = null;
Context context = null;
String to, subject, textMessage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendEmail();
}
});
}
public void sendEmail() {
to = "--------";
Properties props = new Properties();
props.put("mail.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.quitwait", "false");
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
session = Session.getDefaultInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("test@gmail.com", "12341234");
}
});
pdialog = ProgressDialog.show(this, "", "Sending Mail...", true);
RetreiveFeedTask task = new RetreiveFeedTask();
task.execute();
}
class RetreiveFeedTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
try{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("test@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSubject(subject);
message.setContent(textMessage, "text/html; charset=utf-8");
Transport.send(message);
} catch(MessagingException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
pdialog.dismiss();
Toast.makeText(getApplicationContext(), "Message sent", Toast.LENGTH_LONG).show();
}
}
}
Logi:
Spoiler
01-22 12:19:41.188 7136-7136/? D/Zygote: CtrlSocket libc.so ctrl_sockets_set_addr pfunc is not exist!
01-22 12:19:41.198 7136-7136/? I/art: Late-enabling -Xcheck:jni
01-22 12:19:41.248 7136-7136/com.lesson1.myapplication D/ActivityThread: ActivityThread,attachApplication
01-22 12:19:41.278 7136-7136/com.lesson1.myapplication D/HwCust: Create obj success use class android.content.res.HwCustHwResourcesImpl
01-22 12:19:41.298 7136-7136/com.lesson1.myapplication W/System: ClassLoader referenced unknown path: /data/app/com.lesson1.myapplication-2/lib/arm64
01-22 12:19:41.298 7136-7136/com.lesson1.myapplication I/InstantRun: Instant Run Runtime started. Android package is com.lesson1.myapplication, real application class is null.
01-22 12:19:42.258 7136-7136/com.lesson1.myapplication W/System: ClassLoader referenced unknown path: /data/app/com.lesson1.myapplication-2/lib/arm64
01-22 12:19:42.288 7136-7136/com.lesson1.myapplication V/HwPolicyFactory: : success to get AllImpl object and return....
01-22 12:19:42.298 7136-7136/com.lesson1.myapplication V/HwWidgetFactory: : successes to get AllImpl object and return....
01-22 12:19:42.298 7136-7136/com.lesson1.myapplication V/ActivityThread: ActivityThread,callActivityOnCreate
01-22 12:19:42.348 7136-7136/com.lesson1.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
01-22 12:19:42.358 7136-7146/com.lesson1.myapplication I/art: Background sticky concurrent mark sweep GC freed 42631(3MB) AllocSpace objects, 8(188KB) LOS objects, 42% free, 15MB/26MB, paused 6.057ms total 45.630ms
01-22 12:19:42.358 7136-7215/com.lesson1.myapplication D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-22 12:19:42.438 7136-7215/com.lesson1.myapplication I/Adreno: QUALCOMM build : d28da0e, Iec24cdb30f
Build Date : 03/10/16
OpenGL ES Shader Compiler Version: XE031.06.00.05
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.BR.1.2.6_RB1.06.00.01.179.013
Remote Branch : NONE
Reconstruct Branch : NOTHING
01-22 12:19:42.438 7136-7215/com.lesson1.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
01-22 12:19:42.538 7136-7136/com.lesson1.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
01-22 12:19:44.688 7136-7136/com.lesson1.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
01-22 12:19:44.778 7136-7136/com.lesson1.myapplication V/AudioManager: playSoundEffect effectType: 0
01-22 12:19:44.778 7136-7136/com.lesson1.myapplication V/AudioManager: querySoundEffectsEnabled...
01-22 12:19:44.808 7136-7136/com.lesson1.myapplication D/HwSensorManager: HwSensorManager version: 1.0.0
01-22 12:19:44.838 7136-7142/com.lesson1.myapplication W/art: Suspending all threads took: 10.103ms
01-22 12:19:44.878 7136-7136/com.lesson1.myapplication D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.15, mControlPoint1y = 0.7, mControlPoint2x = 0.2, mControlPoint2y = 0.98
01-22 12:19:44.878 7136-7136/com.lesson1.myapplication D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.6, mControlPoint1y = 0.9, mControlPoint2x = 0.8, mControlPoint2y = 1.0
01-22 12:19:44.878 7136-7136/com.lesson1.myapplication V/BoostFramework: mAcquireFunc method = public int com.qualcomm.qti.Performance.perfLockAcquire(int,int[])
01-22 12:19:44.878 7136-7136/com.lesson1.myapplication V/BoostFramework: mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
01-22 12:19:44.878 7136-7136/com.lesson1.myapplication V/BoostFramework: mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent,android.util.DisplayMetrics,int,int[])
01-22 12:19:44.878 7136-7136/com.lesson1.myapplication V/BoostFramework: mIOPStart method = public int com.qualcomm.qti.Performance.perfIOPrefetchStart(int,java.lang.String)
01-22 12:19:44.878 7136-7136/com.lesson1.myapplication V/BoostFramework: mIOPStop method = public int com.qualcomm.qti.Performance.perfIOPrefetchStop()
01-22 12:19:44.888 7136-7136/com.lesson1.myapplication V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@a90ecfc
01-22 12:19:44.888 7136-7136/com.lesson1.myapplication D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.15, mControlPoint1y = 0.7, mControlPoint2x = 0.2, mControlPoint2y = 0.98
01-22 12:19:44.888 7136-7136/com.lesson1.myapplication D/CubicBezierInterpolator: CubicBezierInterpolator mControlPoint1x = 0.6, mControlPoint1y = 0.9, mControlPoint2x = 0.8, mControlPoint2y = 1.0
01-22 12:19:44.888 7136-7136/com.lesson1.myapplication V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@ed1df85
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at com.sun.mail.handlers.text_plain.writeTo(text_plain.java:142)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:897)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at javax.activation.DataHandler.writeTo(DataHandler.java:330)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:261)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1321)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2074)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2042)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at javax.mail.Transport.send(Transport.java:117)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at com.lesson1.myapplication.MainActivity$RetreiveFeedTask.doInBackground(MainActivity.java:87)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at com.lesson1.myapplication.MainActivity$RetreiveFeedTask.doInBackground(MainActivity.java:76)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:307)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
01-22 12:19:45.028 7136-7413/com.lesson1.myapplication W/System.err: at java.lang.Thread.run(Thread.java:833)
01-22 12:19:45.138 7136-7136/com.lesson1.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
01-22 12:20:23.788 7136-7136/com.lesson1.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
01-22 12:20:23.858 7136-7136/com.lesson1.myapplication V/AudioManager: playSoundEffect effectType: 0
01-22 12:20:23.868 7136-7136/com.lesson1.myapplication V/AudioManager: querySoundEffectsEnabled...