-}
-
-
-//
-//
-// public void sendEmail()
-// {
-//
-// private static final int PICK_FROM_GALLERY = 101;
-// int columnIndex;
-// try
-// {
-//
-//
-//
-// final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
-// emailIntent.setType("plain/text");
-// emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "Email" });
-// emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
-// if (URI != null) {
-// emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
-// }
-// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is a message");
-// this.startActivity(Intent.createChooser(emailIntent,"Sending email..."));
-// }
-// catch (Throwable t)
-// {
-// Toast.makeText(this, "Request failed try again: " + t.toString(),Toast.LENGTH_LONG).show();
-// }
-// }
-// public void openFolder()
-// {
-// Intent intent = new Intent();
-// intent.setType("image/*");
-// intent.setAction(Intent.ACTION_GET_CONTENT);
-// intent.putExtra("return-data", true);
-// startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);
-// }
-//
-// public static sendLogs(){
-//
-// }
-//
-// public void SendLoagcatMail(){
-//
-// // save logcat in file
-// /*File outputFile = new File(Environment.getExternalStorageDirectory(),
-// "logcat.txt");
-// try {
-// Runtime.getRuntime().exec(
-// "logcat -f " + outputFile.getAbsolutePath());
-// } catch (IOException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }*/
-// String fname = getExternalFilesDir(null) + File.separator + "log.txt";
-//
-// File logfile = new File(fname);
-//
-// //send file using email
-// Intent emailIntent = new Intent(Intent.ACTION_SEND);
-// emailIntent.setType("vnd.android.cursor.dir/email");
-// String to[] = {"seudut@gmail.com"};
-// emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
-// // the attachment
-// emailIntent.putExtra(Intent.EXTRA_STREAM, logfile.getAbsolutePath());
-// // the mail subject
-// emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
-// startActivity(Intent.createChooser(emailIntent , "Send email..."));
-// }
-
-//}
+ private static final String SMTP_SERVER = "smtp.exmail.qq.com";
+ private static final String USER = "support@suanzi.ai";
+ private static final String SENT_MAIL = "support@suanzi.ai";
+ private static final String PASSWORD = "oqiDX8fcWa58CmNf";
+ private static final String RECV_MAIL = "support@suanzi.ai";
+
+ private static boolean sendMail(String attachment){
+
+ String account = UserInfo.user;
+ String macAddr = UserInfo.macAddr;
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+ StrictMode.setThreadPolicy(policy);
+
+ Properties props = new Properties();
+ props.setProperty("mail.transport.protocol", "smtp");
+ props.setProperty("mail.smtp.host", SMTP_SERVER);
+ props.setProperty("mail.smtp.auth", "true");
+ /*final String smtpPort = "465";
+ props.setProperty("mail.smtp.port", smtpPort);
+ props.setProperty("mail.smtp.socketFactory.class", "javax.NET.ssl.SSLSocketFactory");
+ props.setProperty("mail.smtp.socketFactory.fallback", "false");
+ props.setProperty("mail.smtp.socketFactory.port", smtpPort);*/
+ Session session = Session.getDefaultInstance(props);
+ session.setDebug(true);
+
+ MimeMessage message = new MimeMessage(session);
+ try {
+ message.setFrom(new InternetAddress(SENT_MAIL, account, "UTF-8"));
+ message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(RECV_MAIL, "support", "UTF-8"));
+ message.setSubject(macAddr, "UTF-8");
+ //message.setContent("hahaha", "text/html;charset=UTF-8");
+ message.setSentDate(new Date());
+
+
+ BodyPart messageBodyPart = new MimeBodyPart();
+ messageBodyPart.setText("This is message body");
+ Multipart multipart = new MimeMultipart();
+ multipart.addBodyPart(messageBodyPart);
+ messageBodyPart = new MimeBodyPart();
+ DataSource source = new FileDataSource(attachment);
+ messageBodyPart.setDataHandler(new DataHandler(source));
+
+ String fname = attachment.substring(attachment.lastIndexOf("/") + 1);
+ messageBodyPart.setFileName(fname);
+ multipart.addBodyPart(messageBodyPart);
+
+ // Send the complete message parts
+ message.setContent(multipart);
+ message.saveChanges();
+
+ Transport transport = session.getTransport();
+ transport.connect(USER, PASSWORD);
+ transport.sendMessage(message, message.getAllRecipients());
+ transport.close();
+ } catch (Exception e){
+ gLogger.error("send mail, error: " + e.getMessage());
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ private static final int BUFFER_SIZE = 8192;
+ private static void zip(String[] files, String zipFile) throws IOException {
+ BufferedInputStream origin = null;
+ ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
+
+ try {
+ byte data[] = new byte[BUFFER_SIZE];
+
+ for (int i = 0; i < files.length; i++) {
+ FileInputStream fi = new FileInputStream(files[i]);
+ origin = new BufferedInputStream(fi, BUFFER_SIZE);
+ try {
+ ZipEntry entry = new ZipEntry(files[i].substring(files[i].lastIndexOf("/") + 1));
+ out.putNextEntry(entry);
+ int count;
+ while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
+ out.write(data, 0, count);
+ }
+ }
+ finally {
+ origin.close();
+ }
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ } finally {
+ out.close();
+ }
+ }
+}
\ No newline at end of file