<libaes>feat: 新增SMTP邮件发送启用开关,禁用时sendMail跳过操作
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Fri Jul 17 15:03:05 HKT 2026
|
#Fri Jul 17 19:09:07 HKT 2026
|
||||||
stageCount=20
|
stageCount=20
|
||||||
libraryProject=libaes
|
libraryProject=libaes
|
||||||
baseVersion=15.20
|
baseVersion=15.20
|
||||||
publishVersion=15.20.19
|
publishVersion=15.20.19
|
||||||
buildCount=0
|
buildCount=3
|
||||||
baseBetaVersion=15.20.20
|
baseBetaVersion=15.20.20
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class APPMSGMailUtils {
|
|||||||
private static final String KEY_SMTP_SENDER = "smtp_sender";
|
private static final String KEY_SMTP_SENDER = "smtp_sender";
|
||||||
private static final String KEY_SMTP_AUTH_CODE = "smtp_auth_code";
|
private static final String KEY_SMTP_AUTH_CODE = "smtp_auth_code";
|
||||||
private static final String KEY_SMTP_RECIPIENT = "smtp_recipient";
|
private static final String KEY_SMTP_RECIPIENT = "smtp_recipient";
|
||||||
|
private static final String KEY_SMTP_ENABLED = "smtp_enabled";
|
||||||
|
|
||||||
private static final String DEFAULT_SMTP_SERVER = "smtp.qq.com";
|
private static final String DEFAULT_SMTP_SERVER = "smtp.qq.com";
|
||||||
private static final String DEFAULT_SMTP_PORT = "465";
|
private static final String DEFAULT_SMTP_PORT = "465";
|
||||||
@@ -81,11 +82,31 @@ public class APPMSGMailUtils {
|
|||||||
return sp.getString(KEY_SMTP_RECIPIENT, "");
|
return sp.getString(KEY_SMTP_RECIPIENT, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// SMTP邮件发送开关
|
||||||
|
//
|
||||||
|
public static void setEnabled(Context context, boolean enabled) {
|
||||||
|
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
|
editor.putBoolean(KEY_SMTP_ENABLED, enabled);
|
||||||
|
editor.apply();
|
||||||
|
LogUtils.d(TAG, "setEnabled: " + enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEnabled(Context context) {
|
||||||
|
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
|
||||||
|
return sp.getBoolean(KEY_SMTP_ENABLED, false);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// 发送邮件(异步,在后台线程执行)
|
// 发送邮件(异步,在后台线程执行)
|
||||||
//
|
//
|
||||||
public static void sendMail(final Context context, final String subject,
|
public static void sendMail(final Context context, final String subject,
|
||||||
final String content, final String recipients) {
|
final String content, final String recipients) {
|
||||||
|
if (!isEnabled(context)) {
|
||||||
|
LogUtils.d(TAG, "sendMail: SMTP邮件发送已禁用,跳过操作");
|
||||||
|
return;
|
||||||
|
}
|
||||||
final String server = getServer(context);
|
final String server = getServer(context);
|
||||||
final String port = getPort(context);
|
final String port = getPort(context);
|
||||||
final String sender = getSender(context);
|
final String sender = getSender(context);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package cc.winboll.studio.libaes.views;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -24,6 +26,7 @@ public class SMTPConfigView extends LinearLayout {
|
|||||||
private EditText mEtSender;
|
private EditText mEtSender;
|
||||||
private EditText mEtAuthCode;
|
private EditText mEtAuthCode;
|
||||||
private EditText mEtRecipient;
|
private EditText mEtRecipient;
|
||||||
|
private CheckBox mCbEnabled;
|
||||||
|
|
||||||
public SMTPConfigView(Context context) {
|
public SMTPConfigView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -44,6 +47,14 @@ public class SMTPConfigView extends LinearLayout {
|
|||||||
mEtSender = (EditText) findViewById(R.id.et_smtp_sender);
|
mEtSender = (EditText) findViewById(R.id.et_smtp_sender);
|
||||||
mEtAuthCode = (EditText) findViewById(R.id.et_smtp_auth_code);
|
mEtAuthCode = (EditText) findViewById(R.id.et_smtp_auth_code);
|
||||||
mEtRecipient = (EditText) findViewById(R.id.et_smtp_recipient);
|
mEtRecipient = (EditText) findViewById(R.id.et_smtp_recipient);
|
||||||
|
mCbEnabled = (CheckBox) findViewById(R.id.cb_smtp_enabled);
|
||||||
|
|
||||||
|
mCbEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
APPMSGMailUtils.setEnabled(getContext(), isChecked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 加载已保存的配置
|
// 加载已保存的配置
|
||||||
loadConfig();
|
loadConfig();
|
||||||
@@ -80,6 +91,7 @@ public class SMTPConfigView extends LinearLayout {
|
|||||||
mEtSender.setText(APPMSGMailUtils.getSender(context));
|
mEtSender.setText(APPMSGMailUtils.getSender(context));
|
||||||
mEtAuthCode.setText(APPMSGMailUtils.getAuthCode(context));
|
mEtAuthCode.setText(APPMSGMailUtils.getAuthCode(context));
|
||||||
mEtRecipient.setText(APPMSGMailUtils.getRecipient(context));
|
mEtRecipient.setText(APPMSGMailUtils.getRecipient(context));
|
||||||
|
mCbEnabled.setChecked(APPMSGMailUtils.isEnabled(context));
|
||||||
LogUtils.d(TAG, "loadConfig: SMTP配置已加载");
|
LogUtils.d(TAG, "loadConfig: SMTP配置已加载");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,14 @@
|
|||||||
android:hint="recipient@example.com"
|
android:hint="recipient@example.com"
|
||||||
android:inputType="textEmailAddress"/>
|
android:inputType="textEmailAddress"/>
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/cb_smtp_enabled"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="启用SMTP邮件发送"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:layout_marginTop="12dp"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_smtp_save"
|
android:id="@+id/btn_smtp_save"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user