Не отправляется сообщение SMTP Mail сервер (Android Studio)
Я новичок в программирование. Подскажите пожалуйста. Кнопка работает, но не приходит сообщение на электронную почту. С чем связанна такая ошибка, что не приходит сообщение на электронную почту? И как можно устранить такую ошибку?
Заранее спасибо за ответ.
MainActivity
public void ButtonEmail(View view) {
try {
String stringSenderEmail = "********@mail.ru";
String stringReceiverEmail = "********@mail.ru";
String stringPasswordSenderEmail = "123";
String stringHost = "smtp.mail.ru";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", stringHost);
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.auth", "true");
javax.mail.Session session = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(stringPasswordSenderEmail,stringSenderEmail);
}
});
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(stringReceiverEmail));
mimeMessage.setSubject("Subject: Android email");
mimeMessage.setText("Hello");
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Transport.send(mimeMessage);
} catch (MessagingException e) {
e.printStackTrace();
}
}
});
thread.start();
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
manifest
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
buildgradle (app)
apply plugin: 'com.android.application'
android {
compileSdk 31
defaultConfig {
applicationId "zhangman.github.snake"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
packagingOptions{
exclude 'META-INF/NOTICE.md'
exclude 'META-INF/LICENSE.md'
}
buildToolsVersion '30.0.3'
sourceSets {
main {
assets {
srcDirs 'src\\main\\assets'
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation 'com.sun.mail:android-mail:1.6.6'
implementation 'com.sun.mail:android-activation:1.6.7'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}