diff --git a/app/src/main/java/com/idormy/sms/forwarder/SenderActivity.java b/app/src/main/java/com/idormy/sms/forwarder/SenderActivity.java index 1a51aed4c5..3626f4d429 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/SenderActivity.java +++ b/app/src/main/java/com/idormy/sms/forwarder/SenderActivity.java @@ -362,7 +362,9 @@ private void setEmail(final SenderModel senderModel) { final EditText editTextEmailPsw = view1.findViewById(R.id.editTextEmailPsw); final EditText editTextEmailToAdd = view1.findViewById(R.id.editTextEmailToAdd); final EditText editTextEmailTitle = view1.findViewById(R.id.editTextEmailTitle); + final RadioGroup radioGroupEmailProtocol = view1.findViewById(R.id.radioGroupEmailProtocol); if (emailSettingVo != null) { + radioGroupEmailProtocol.check(emailSettingVo.getEmailProtocolCheckId()); editTextEmailHost.setText(emailSettingVo.getHost()); editTextEmailPort.setText(emailSettingVo.getPort()); switchEmailSSl.setChecked(emailSettingVo.getSsl()); @@ -384,21 +386,31 @@ private void setEmail(final SenderModel senderModel) { final AlertDialog show = alertDialog71.show(); buttonEmailOk.setOnClickListener(view -> { + String protocol = radioGroupEmailProtocol.getCheckedRadioButtonId() == R.id.radioEmailProtocolSmtp ? "SMTP" : "IMAP"; + String host = editTextEmailHost.getText().toString().trim(); + String port = editTextEmailPort.getText().toString().trim(); + boolean ssl = switchEmailSSl.isChecked(); + String fromEmail = editTextEmailFromAdd.getText().toString().trim(); + String pwd = editTextEmailPsw.getText().toString().trim(); + String toEmail = editTextEmailToAdd.getText().toString().trim(); + + String title = editTextEmailTitle.getText().toString().trim(); + if (title.isEmpty()) title = "SmsForwarder Title"; + + String nickname = editTextEmailNickname.getText().toString().trim(); + if (nickname.isEmpty()) nickname = "SmsForwarder"; + if (host.isEmpty() || port.isEmpty() || fromEmail.isEmpty() || pwd.isEmpty() || toEmail.isEmpty()) { + Toast.makeText(SenderActivity.this, R.string.invalid_email, Toast.LENGTH_LONG).show(); + return; + } + + EmailSettingVo emailSettingVoNew = new EmailSettingVo(protocol, host, port, ssl, fromEmail, nickname, pwd, toEmail, title); + if (senderModel == null) { SenderModel newSenderModel = new SenderModel(); newSenderModel.setName(editTextEmailName.getText().toString().trim()); newSenderModel.setType(TYPE_EMAIL); newSenderModel.setStatus(STATUS_ON); - EmailSettingVo emailSettingVoNew = new EmailSettingVo( - editTextEmailHost.getText().toString().trim(), - editTextEmailPort.getText().toString().trim(), - switchEmailSSl.isChecked(), - editTextEmailFromAdd.getText().toString().trim(), - editTextEmailNickname.getText().toString().trim(), - editTextEmailPsw.getText().toString().trim(), - editTextEmailToAdd.getText().toString().trim(), - editTextEmailTitle.getText().toString().trim() - ); newSenderModel.setJsonSetting(JSON.toJSONString(emailSettingVoNew)); SenderUtil.addSender(newSenderModel); initSenders(); @@ -407,16 +419,6 @@ private void setEmail(final SenderModel senderModel) { senderModel.setName(editTextEmailName.getText().toString().trim()); senderModel.setType(TYPE_EMAIL); senderModel.setStatus(STATUS_ON); - EmailSettingVo emailSettingVoNew = new EmailSettingVo( - editTextEmailHost.getText().toString().trim(), - editTextEmailPort.getText().toString().trim(), - switchEmailSSl.isChecked(), - editTextEmailFromAdd.getText().toString().trim(), - editTextEmailNickname.getText().toString().trim(), - editTextEmailPsw.getText().toString().trim(), - editTextEmailToAdd.getText().toString().trim(), - editTextEmailTitle.getText().toString().trim() - ); senderModel.setJsonSetting(JSON.toJSONString(emailSettingVoNew)); SenderUtil.updateSender(senderModel); initSenders(); @@ -434,6 +436,7 @@ private void setEmail(final SenderModel senderModel) { show.dismiss(); }); buttonEmailTest.setOnClickListener(view -> { + String protocol = radioGroupEmailProtocol.getCheckedRadioButtonId() == R.id.radioEmailProtocolSmtp ? "SMTP" : "IMAP"; String host = editTextEmailHost.getText().toString().trim(); String port = editTextEmailPort.getText().toString().trim(); boolean ssl = switchEmailSSl.isChecked(); @@ -449,7 +452,7 @@ private void setEmail(final SenderModel senderModel) { if (!host.isEmpty() && !port.isEmpty() && !fromEmail.isEmpty() && !pwd.isEmpty() && !toEmail.isEmpty()) { try { - SenderMailMsg.sendEmail(0, handler, host, port, ssl, fromEmail, nickname, pwd, toEmail, title, R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))); + SenderMailMsg.sendEmail(0, handler, protocol, host, port, ssl, fromEmail, nickname, pwd, toEmail, title, R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))); } catch (Exception e) { Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); diff --git a/app/src/main/java/com/idormy/sms/forwarder/model/vo/EmailSettingVo.java b/app/src/main/java/com/idormy/sms/forwarder/model/vo/EmailSettingVo.java index 6baf95a041..9ce4eee594 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/model/vo/EmailSettingVo.java +++ b/app/src/main/java/com/idormy/sms/forwarder/model/vo/EmailSettingVo.java @@ -1,5 +1,7 @@ package com.idormy.sms.forwarder.model.vo; +import com.idormy.sms.forwarder.R; + import java.io.Serializable; import lombok.Data; @@ -14,11 +16,13 @@ public class EmailSettingVo implements Serializable { private String pwd; private String toEmail; private String title; + private String protocol; public EmailSettingVo() { } - public EmailSettingVo(String host, String port, Boolean ssl, String fromEmail, String nickname, String pwd, String toEmail, String title) { + public EmailSettingVo(String protocol, String host, String port, Boolean ssl, String fromEmail, String nickname, String pwd, String toEmail, String title) { + this.protocol = protocol; this.host = host; this.port = port; this.ssl = ssl; @@ -29,4 +33,11 @@ public EmailSettingVo(String host, String port, Boolean ssl, String fromEmail, S this.title = title; } + public int getEmailProtocolCheckId() { + if (protocol == null || protocol.equals("SMTP")) { + return R.id.radioEmailProtocolSmtp; + } else { + return R.id.radioEmailProtocolImap; + } + } } diff --git a/app/src/main/java/com/idormy/sms/forwarder/sender/SendUtil.java b/app/src/main/java/com/idormy/sms/forwarder/sender/SendUtil.java index 7419829d3f..7cce4ee624 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/sender/SendUtil.java +++ b/app/src/main/java/com/idormy/sms/forwarder/sender/SendUtil.java @@ -132,7 +132,7 @@ public static void senderSendMsg(Handler handError, SmsVo smsVo, SenderModel sen EmailSettingVo emailSettingVo = JSON.parseObject(senderModel.getJsonSetting(), EmailSettingVo.class); if (emailSettingVo != null) { try { - SenderMailMsg.sendEmail(logId, handError, emailSettingVo.getHost(), emailSettingVo.getPort(), emailSettingVo.getSsl(), emailSettingVo.getFromEmail(), emailSettingVo.getNickname(), + SenderMailMsg.sendEmail(logId, handError, emailSettingVo.getProtocol(), emailSettingVo.getHost(), emailSettingVo.getPort(), emailSettingVo.getSsl(), emailSettingVo.getFromEmail(), emailSettingVo.getNickname(), emailSettingVo.getPwd(), emailSettingVo.getToEmail(), smsVo.getTitleForSend(emailSettingVo.getTitle()), smsVo.getSmsVoForSend(smsTemplate)); } catch (Exception e) { LogUtil.updateLog(logId, 0, e.getMessage()); diff --git a/app/src/main/java/com/idormy/sms/forwarder/sender/SenderMailMsg.java b/app/src/main/java/com/idormy/sms/forwarder/sender/SenderMailMsg.java index 15a66b6f02..112a83de34 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/sender/SenderMailMsg.java +++ b/app/src/main/java/com/idormy/sms/forwarder/sender/SenderMailMsg.java @@ -18,9 +18,9 @@ public class SenderMailMsg extends SenderBaseMsg { private static final String TAG = "SenderMailMsg"; - public static void sendEmail(final long logId, final Handler handError, final String host, final String port, final boolean ssl, final String fromEmail, final String nickname, final String pwd, final String toAdd, final String title, final String content) { + public static void sendEmail(final long logId, final Handler handError, final String protocol, final String host, final String port, final boolean ssl, final String fromEmail, final String nickname, final String pwd, final String toAdd, final String title, final String content) { - Log.d(TAG, "sendEmail: host:" + host + " port:" + port + " ssl:" + ssl + " fromEmail:" + fromEmail + " nickname:" + nickname + " pwd:" + pwd + " toAdd:" + toAdd); + Log.d(TAG, "sendEmail: protocol:" + protocol + " host:" + host + " port:" + port + " ssl:" + ssl + " fromEmail:" + fromEmail + " nickname:" + nickname + " pwd:" + pwd + " toAdd:" + toAdd); Observable .create((ObservableEmitter emitter) -> { diff --git a/app/src/main/res/layout/alert_dialog_setview_email.xml b/app/src/main/res/layout/alert_dialog_setview_email.xml index bd1ed0812b..dc0bbf6a53 100644 --- a/app/src/main/res/layout/alert_dialog_setview_email.xml +++ b/app/src/main/res/layout/alert_dialog_setview_email.xml @@ -33,6 +33,16 @@ tools:ignore="LabelFor,TextFields" /> + + + android:text="@string/email_account" /> + tools:ignore="LabelFor" /> + android:text="@string/email_password" /> + + + + android:text="@string/email_nickname" /> - + android:layout_marginStart="3dp" + android:autofillHints="" + android:ems="14" + android:inputType="text" + android:text="" + tools:ignore="LabelFor,TextFields" /> + + + android:layout_marginTop="5dp" + android:orientation="horizontal" + android:visibility="gone"> + android:paddingTop="5dp" + android:text="@string/email_protocol" /> - + android:orientation="horizontal"> + + + + + + + + android:text="@string/email_host" /> + android:text="@string/smtp_port" /> + + + + + + @@ -253,7 +322,7 @@ android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:layout_weight="1" - android:background="@color/colorPrimary" + android:background="@color/colorBlueGrey" android:text="@string/insert_extra" tools:ignore="ButtonStyle,NestedWeights" /> @@ -265,7 +334,7 @@ android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:layout_weight="1" - android:background="@color/colorPrimary" + android:background="@color/colorBlueGrey" android:text="@string/insert_time" tools:ignore="ButtonStyle,NestedWeights" /> @@ -277,7 +346,7 @@ android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:layout_weight="1" - android:background="@color/colorPrimary" + android:background="@color/colorBlueGrey" android:text="@string/insert_device_name" tools:ignore="ButtonStyle,NestedWeights" /> diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 7e7145a2ce..f2bfcfd7b7 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -122,8 +122,11 @@ Token e.g. the XXXXXX part of https://oapi.dingtalk.com/robot/send?access_token=XXXXXX Secret (optional) At Mobiles e.g. 18888888888,19999999999 - SMTP Host - SMTP Port + Protocol + SMTP + IMAP + Server Host + Server Port SSL Account Password/Auth Code @@ -238,4 +241,7 @@ Callback Url Valid time(secs) wechat + ✱Account + ✱Servers + ✱Email diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b492aa84c1..cc41bfb5d4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -122,10 +122,13 @@ 设置Token 例如 https://oapi.dingtalk.com/robot/send?access_token=XXXXXX 中的 XXXXXX 加签 Secret (没有可不填) 转发时@某人 填写某人的手机号,多个用逗号分开 例如:18888888888,19999999999 - SMTP服务器 - SMTP端口 + 协议类型 + SMTP + IMAP + 服务器地址 + 服务器端口 开启SSL - 发件人帐号 + 发件人邮箱 登录密码/授权码 发件人昵称 收件地址 @@ -237,4 +240,7 @@ 回调地址 有效时间(秒) wechat + ✱帐户管理 + ✱服务器信息 + ✱邮件设置