send emails
This commit is contained in:
1 parent
41cfeb43fc
commit
4e88587b13
5 files changed
+141
-23
No files matched your search
+1
-1
@@ -66,7 +66,7 @@ android {
|
||||
buildToolsVersion '36.0.0'
|
||||
}
|
||||
|
||||
{
|
||||
dependencies {
|
||||
implementation 'org.jetbrains:annotations:26.1.0'
|
||||
googlePlayFlavorImplementation 'com.google.firebase:firebase-appindexing:20.0.0'
|
||||
googlePlayFlavorImplementation 'com.google.android.gms:play-services-location:20.0.0'
|
||||
|
||||
@@ -7,14 +7,12 @@ import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningServiceInfo;
|
||||
import android.app.Notification;
|
||||
import android.app.Notification.Builder;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
@@ -37,7 +35,6 @@ import com.jens.automation2.receivers.DateTimeListener;
|
||||
import com.jens.automation2.receivers.PackageReplacedReceiver;
|
||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
@@ -45,8 +42,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
@@ -439,24 +434,32 @@ public class AutomationService extends Service implements OnInitListener
|
||||
Settings.writeSettings(Miscellaneous.getAnyContext());
|
||||
}
|
||||
|
||||
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
|
||||
EmailService es = new EmailService(Settings.smtpServerName, Integer.parseInt(Settings.smtpServerPort));
|
||||
// try
|
||||
// {
|
||||
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
|
||||
EmailService es = new EmailService(Settings.smtpServerHostname, Integer.parseInt(Settings.smtpServerPort));
|
||||
|
||||
List addresses = new ArrayList();
|
||||
addresses.add(Settings.smtpFromAddress);
|
||||
try
|
||||
{
|
||||
EmailService.Email em = new EmailService.Email(new EmailService.UserPassAuthenticator(Settings.smtpUsername, Settings.smtpPassword), addresses, new InternetAddress(String.valueOf(addresses.get(0))), "test", "testbody");
|
||||
es.send(em);
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
List addresses = new ArrayList();
|
||||
addresses.add(Settings.smtpFromAddress);
|
||||
try
|
||||
{
|
||||
EmailService.Email em = new EmailService.Email(new EmailService.UserPassAuthenticator(Settings.smtpUsername, Settings.smtpPassword), addresses, new InternetAddress(String.valueOf(addresses.get(0))), "test", "testbody");
|
||||
es.send(em);
|
||||
Miscellaneous.logEvent("i", "sendEmail()", "Email sent.", 1);
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// }
|
||||
// catch(Exception e)
|
||||
// {
|
||||
// Miscellaneous.logEvent("e", "sendMail()", Log.getStackTraceString(e), 1);
|
||||
// }
|
||||
|
||||
Settings.serviceStartDone = true;
|
||||
Settings.deviceStartDone = true;
|
||||
|
||||
@@ -73,6 +73,14 @@ public class Settings implements SharedPreferences
|
||||
public static long musicCheckFrequency;
|
||||
public static String displayLanguage;
|
||||
|
||||
public static String smtpServerHostname;
|
||||
public static String smtpServerPort;
|
||||
public static boolean smtpServerUseTls;
|
||||
public static String smtpFromAddress;
|
||||
public static String smtpToAddress;
|
||||
public static String smtpUsername;
|
||||
public static String smtpPassword;
|
||||
|
||||
public static boolean lockSoundChanges;
|
||||
public static boolean noticeAndroid9MicrophoneShown;
|
||||
public static boolean noticeAndroid10WifiShown;
|
||||
@@ -146,6 +154,14 @@ public class Settings implements SharedPreferences
|
||||
public static final long default_musicCheckFrequency = 2500;
|
||||
public static final String default_displayLanguage = "systemDefaultLanguage";
|
||||
|
||||
public static final String default_smtpServerHostname = "";
|
||||
public static final String default_smtpServerPort = "587";
|
||||
public static final boolean default_smtpServerUseTls = false;
|
||||
public static final String default_smtpFromAddress = "";
|
||||
public static final String default_smtpToAddress = "";
|
||||
public static final String default_smtpUsername = "";
|
||||
public static final String default_smtpPassword = "";
|
||||
|
||||
@Override
|
||||
public boolean contains(String arg0)
|
||||
{
|
||||
@@ -273,6 +289,14 @@ public class Settings implements SharedPreferences
|
||||
musicCheckFrequency = Long.parseLong(prefs.getString("musicCheckFrequency", String.valueOf(default_musicCheckFrequency)));
|
||||
displayLanguage = prefs.getString("displayLanguage", default_displayLanguage);
|
||||
|
||||
smtpServerHostname = prefs.getString("smtpServerHostname", default_smtpServerHostname);
|
||||
smtpServerPort = prefs.getString("smtpServerPort", default_smtpServerPort);
|
||||
smtpServerUseTls = prefs.getBoolean("smtpServerUseTls", default_smtpServerUseTls);
|
||||
smtpFromAddress = prefs.getString("smtpFromAddress", default_smtpFromAddress);
|
||||
smtpToAddress = prefs.getString("smtpToAddress", default_smtpToAddress);
|
||||
smtpUsername = prefs.getString("smtpUsername", default_smtpUsername);
|
||||
smtpPassword = prefs.getString("smtpPassword", default_smtpPassword);
|
||||
|
||||
if(Settings.musicCheckFrequency == 0)
|
||||
Settings.musicCheckFrequency = Settings.default_musicCheckFrequency;
|
||||
|
||||
@@ -490,6 +514,27 @@ public class Settings implements SharedPreferences
|
||||
if(!prefs.contains("displayLanguage") || force)
|
||||
editor.putString("displayLanguage", default_displayLanguage);
|
||||
|
||||
if(!prefs.contains("smtpServerHostname") || force)
|
||||
editor.putString("smtpServerHostname", default_smtpServerHostname);
|
||||
|
||||
if(!prefs.contains("smtpServerPort") || force)
|
||||
editor.putString("smtpServerPort", default_smtpServerPort);
|
||||
|
||||
if(!prefs.contains("smtpServerUseTls") || force)
|
||||
editor.putBoolean("smtpServerUseTls", default_smtpServerUseTls);
|
||||
|
||||
if(!prefs.contains("smtpFromAddress") || force)
|
||||
editor.putString("smtpFromAddress", default_smtpFromAddress);
|
||||
|
||||
if(!prefs.contains("smtpToAddress") || force)
|
||||
editor.putString("smtpToAddress", default_smtpToAddress);
|
||||
|
||||
if(!prefs.contains("smtpUsername") || force)
|
||||
editor.putString("smtpUsername", default_smtpUsername);
|
||||
|
||||
if(!prefs.contains("smtpPassword") || force)
|
||||
editor.putString("smtpPassword", default_smtpPassword);
|
||||
|
||||
if(!prefs.contains("lockSoundChanges") || force)
|
||||
editor.putBoolean("lockSoundChanges", default_lockSoundChanges);
|
||||
|
||||
@@ -580,6 +625,14 @@ public class Settings implements SharedPreferences
|
||||
|
||||
editor.putString("displayLanguage", displayLanguage);
|
||||
|
||||
editor.putString("smtpServerHostname", smtpServerHostname);
|
||||
editor.putString("smtpServerPort", smtpServerPort);
|
||||
editor.putBoolean("smtpServerUseTls", smtpServerUseTls);
|
||||
editor.putString("smtpFromAddress", smtpFromAddress);
|
||||
editor.putString("smtpToAddress", smtpToAddress);
|
||||
editor.putString("smtpUsername", smtpUsername);
|
||||
editor.putString("smtpPassword", smtpPassword);
|
||||
|
||||
editor.putBoolean("lockSoundChanges", lockSoundChanges);
|
||||
editor.putBoolean("noticeAndroid9MicrophoneShown", noticeAndroid9MicrophoneShown);
|
||||
editor.putBoolean("noticeAndroid10WifiShown", noticeAndroid10WifiShown);
|
||||
|
||||
@@ -307,5 +307,52 @@
|
||||
android:inputType="number" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:summary="@string/settingsCategorySendEmails"
|
||||
android:title="@string/settingsCategorySendEmails">
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpServerHostname"
|
||||
android:summary="@string/smtpServerHostnameSummary"
|
||||
android:title="@string/smtpServerHostnameTitle"
|
||||
android:inputType="text" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpServerPort"
|
||||
android:summary="@string/smtpServerPortSummary"
|
||||
android:title="@string/smtpServerPortTitle"
|
||||
android:inputType="number" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="smtpServerUseTls"
|
||||
android:summary="@string/smtpServerUseTlsSummary"
|
||||
android:title="@string/smtpServerUseTlsTitle" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpFromAddress"
|
||||
android:summary="@string/smtpFromAddressSummary"
|
||||
android:title="@string/smtpFromAddressTitle"
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpToAddress"
|
||||
android:summary="@string/smtpToAddressSummary"
|
||||
android:title="@string/smtpToAddressTitle"
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpUsername"
|
||||
android:summary="@string/smtpUsernameSummary"
|
||||
android:title="@string/smtpUsernameTitle"
|
||||
android:inputType="text" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpPassword"
|
||||
android:summary="@string/smtpPasswordSummary"
|
||||
android:title="@string/smtpPasswordTitle"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -980,4 +980,19 @@
|
||||
<string name="httpParametersExplanation">If any parameter name starts with %1$s while method is POST, it will not be transmitted like the other parameters (with key=value), but transferred as main data. If the parameter ends with %2$s, no encoding will be performed.</string>
|
||||
<string name="target">Target</string>
|
||||
<string name="enter_valid_url">Enter a valid URL.</string>
|
||||
<string name="settingsCategorySendEmails">Email server settings</string>
|
||||
<string name="smtpServerHostnameTitle">Hostname</string>
|
||||
<string name="smtpServerHostnameSummary">SMTP server hostname</string>
|
||||
<string name="smtpServerPortTitle">Port</string>
|
||||
<string name="smtpServerPortSummary">SMTP server port</string>
|
||||
<string name="smtpServerUseTlsTitle">Use TLS</string>
|
||||
<string name="smtpServerUseTlsSummary">Use TLS for connection to SMTP server</string>
|
||||
<string name="smtpFromAddressTitle">From address</string>
|
||||
<string name="smtpFromAddressSummary">Sender address emails (from)</string>
|
||||
<string name="smtpToAddressTitle">Recipient address</string>
|
||||
<string name="smtpToAddressSummary">Recipient address for emails (to)</string>
|
||||
<string name="smtpUsernameTitle">Username</string>
|
||||
<string name="smtpUsernameSummary">Leave empty for no authentication</string>
|
||||
<string name="smtpPasswordTitle">Password</string>
|
||||
<string name="smtpPasswordSummary">If username is empty, no authentication is used.</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user