parent
9360bbb5e2
commit
6d89e25d38
Binary file not shown.
@ -1,147 +0,0 @@
|
||||
package com.idormy.sms.forwarder.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.sun.mail.util.MailSSLSocketFactory;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MailSenderInfo {
|
||||
private static String TAG = "MailSenderInfo";
|
||||
// 发送邮件的服务器的IP和端口
|
||||
private String mailServerHost;
|
||||
private String mailServerPort = "25";
|
||||
|
||||
// 邮件发送者的地址
|
||||
private String fromAddress;
|
||||
// 邮件接收者的地址
|
||||
private String toAddress;
|
||||
// 登陆邮件发送服务器的用户名和密码
|
||||
private String userName;
|
||||
private String password;
|
||||
// 是否需要身份验证
|
||||
private boolean validate = true;
|
||||
//开启ssl
|
||||
private boolean ssl = true;
|
||||
// 邮件主题
|
||||
private String subject;
|
||||
// 邮件的文本内容
|
||||
private String content;
|
||||
// 邮件附件的文件名
|
||||
private String[] attachFileNames;
|
||||
|
||||
/**
|
||||
* 获得邮件会话属性
|
||||
*/
|
||||
public Properties getProperties() {
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.host", this.mailServerHost);
|
||||
props.put("mail.smtp.port", this.mailServerPort);
|
||||
props.put("mail.smtp.auth", validate ? "true" : "false");
|
||||
|
||||
if (ssl) {
|
||||
try {
|
||||
MailSSLSocketFactory sf = new MailSSLSocketFactory();
|
||||
sf.setTrustAllHosts(true);
|
||||
props.put("mail.smtp.ssl.enable", "true");
|
||||
props.put("mail.smtp.ssl.socketFactory", sf);
|
||||
Log.i(TAG, "set ssl success");
|
||||
} catch (GeneralSecurityException e) {
|
||||
Log.e(TAG, "set ssl fail: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
public String getMailServerHost() {
|
||||
return mailServerHost;
|
||||
}
|
||||
|
||||
public void setMailServerHost(String mailServerHost) {
|
||||
this.mailServerHost = mailServerHost;
|
||||
}
|
||||
|
||||
public String getMailServerPort() {
|
||||
return mailServerPort;
|
||||
}
|
||||
|
||||
public void setMailServerPort(String mailServerPort) {
|
||||
this.mailServerPort = mailServerPort;
|
||||
}
|
||||
|
||||
public boolean isValidate() {
|
||||
return validate;
|
||||
}
|
||||
|
||||
public void setValidate(boolean validate) {
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
public String[] getAttachFileNames() {
|
||||
return attachFileNames;
|
||||
}
|
||||
|
||||
public void setAttachFileNames(String[] fileNames) {
|
||||
this.attachFileNames = fileNames;
|
||||
}
|
||||
|
||||
public String getFromAddress() {
|
||||
return fromAddress;
|
||||
}
|
||||
|
||||
public void setFromAddress(String fromAddress) {
|
||||
this.fromAddress = fromAddress;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getToAddress() {
|
||||
return toAddress;
|
||||
}
|
||||
|
||||
public void setToAddress(String toAddress) {
|
||||
this.toAddress = toAddress;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String textContent) {
|
||||
this.content = textContent;
|
||||
}
|
||||
|
||||
public boolean isSsl() {
|
||||
return ssl;
|
||||
}
|
||||
|
||||
public void setSsl(boolean ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package com.idormy.sms.forwarder.utils;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
|
||||
public class MyAuthenticator extends Authenticator {
|
||||
String userName = null;
|
||||
String password = null;
|
||||
|
||||
public MyAuthenticator() {
|
||||
}
|
||||
|
||||
public MyAuthenticator(String username, String password) {
|
||||
this.userName = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(userName, password);
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package com.idormy.sms.forwarder.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
public class SendMailUtil {
|
||||
private static String TAG = "SendMailUtil";
|
||||
//qq
|
||||
// private static final String HOST = "smtp.qq.com";
|
||||
// private static final String PORT = "587";
|
||||
// private static final String FROM_ADD = "teprinciple@foxmail.com"; //发送方邮箱
|
||||
// private static final String FROM_PSW = "lfrlpganzjrwbeci";//发送方邮箱授权码
|
||||
|
||||
// //163
|
||||
// private static final String HOST = "smtp.163.com";
|
||||
// private static final String PORT = "465"; //nossl 25或者ssl465 994
|
||||
// private static final String FROM_ADD = "xxxxxx@163.com";
|
||||
// private static final String FROM_PSW = "xx";
|
||||
|
||||
public static void send(final File file, String toAdd, String title, String content) {
|
||||
Log.d(TAG, "send file to " + toAdd);
|
||||
final MailInfo mailInfo = creatMail(toAdd, title, content);
|
||||
final MailSender sms = new MailSender();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sms.sendFileMail(mailInfo, file);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static void send(String toAdd, String title, String content) {
|
||||
Log.d(TAG, "send to " + toAdd);
|
||||
final MailInfo mailInfo = creatMail(toAdd, title, content);
|
||||
final MailSender sms = new MailSender();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sms.sendTextMail(mailInfo);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private static MailInfo creatMail(String toAdd, String title, String content) {
|
||||
Log.d(TAG, "creatMail to " + toAdd);
|
||||
final MailInfo mailInfo = new MailInfo();
|
||||
mailInfo.setMailServerHost(SettingUtil.get_send_util_email(Define.SP_MSG_SEND_UTIL_EMAIL_HOST_KEY));
|
||||
mailInfo.setMailServerPort(SettingUtil.get_send_util_email(Define.SP_MSG_SEND_UTIL_EMAIL_PORT_KEY));
|
||||
mailInfo.setValidate(true);
|
||||
mailInfo.ssl(true);
|
||||
mailInfo.setUserName(SettingUtil.get_send_util_email(Define.SP_MSG_SEND_UTIL_EMAIL_FROMADD_KEY)); // 你的邮箱地址
|
||||
mailInfo.setPassword(SettingUtil.get_send_util_email(Define.SP_MSG_SEND_UTIL_EMAIL_PSW_KEY));// 您的邮箱密码
|
||||
mailInfo.setFromAddress(SettingUtil.get_send_util_email(Define.SP_MSG_SEND_UTIL_EMAIL_FROMADD_KEY)); // 发送的邮箱
|
||||
mailInfo.setToAddress(SettingUtil.get_send_util_email(Define.SP_MSG_SEND_UTIL_EMAIL_TOADD_KEY)); // 发到哪个邮件去
|
||||
mailInfo.setSubject(title); // 邮件主题
|
||||
mailInfo.setContent(content); // 邮件文本
|
||||
return mailInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* public void sendFileMail(View view) {
|
||||
* <p>
|
||||
* File file = new File(Environment.getExternalStorageDirectory()+File.separator+"test.txt");
|
||||
* OutputStream os = null;
|
||||
* try {
|
||||
* os = new FileOutputStream(file);
|
||||
* String str = "hello world";
|
||||
* byte[] data = str.getBytes();
|
||||
* os.write(data);
|
||||
* } catch (FileNotFoundException e) {
|
||||
* e.printStackTrace();
|
||||
* } catch (IOException e) {
|
||||
* e.printStackTrace();
|
||||
* }finally{
|
||||
* try {
|
||||
* if (os != null)os.close();
|
||||
* } catch (IOException e) {
|
||||
* }
|
||||
* }
|
||||
* SendMailUtil.send(file,editText.getText().toString());
|
||||
* }
|
||||
*/
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
Loading…
Reference in New Issue