how to resolve java smtpclass bug in android

i want send email to a group of people with separate content ( ever person with a special content ).

i use timer because i have a progressbar. this is my code :

.............. .............. timer.schedule(new TimerTask() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { if (progress.getProgress() == 100){ timer.cancel(); closeBtn.setVisibility(View.VISIBLE); } int current_index = 1; for (String sid : SID) { String html = ReportGenerator.getHtmlContent( current_index ); if (email) { String rec_email[] = new String[1]; rec_email[0] = emailList.get( current_index ); mail.setSubject(ctx.getString(R.string.ReportDialog_email)); mail.setTo(rec_email); mail.setFrom(FROM); mail.setBody(html); try { boolean i = mail.send(); if (i) { Toast.makeText(ctx, "Email was sent successfully ", Toast.LENGTH_LONG).show(); } else { Toast.makeText(ctx, "Email was not sent successfully ", Toast.LENGTH_LONG).show(); } } catch (Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } progress.setProgress(Math.round((current_index / SID.size()) * 100)); current_index += 1; } } }); } }, 1000, 100); ................

email sent successfully but over and over ( in endless loop ) until program closed by force ( force closing )

this is my smtp class :

package com.example.habib.share; import; import; import; import; import java.util.Date; import java.util.Properties; import javax.activation.CommandMap; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.activation.MailcapCommandMap; import javax.mail.BodyPart; import javax.mail.Multipart; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import android.util.Log; public class Mail extends javax.mail.Authenticator { private String _user; private String _pass; private String[] _to; private String _from; private String _port; private String _sport; private String _host; private String _subject; private String _body; private boolean _auth; private boolean _debuggable; private Multipart _multipart; public Mail() { _host = ""; // default smtp server _port = "465"; // default smtp port _sport = "465"; // default socketfactory port _user = ""; // username _pass = ""; // password _from = ""; // email sent from _subject = ""; // email subject _body = ""; // email body _debuggable = false; // debug mode on or off - default off _auth = true; // smtp authentication - default on _multipart = new MimeMultipart(); // There is something wrong with MailCap, javamail can not find a handler for the multipart/mixed part, so this bit needs to be added. MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822"); CommandMap.setDefaultCommandMap(mc); } public Mail(String user, String pass) { this(); _user = user; _pass = pass; } public boolean send() throws Exception { Properties props = _setProperties(); if(!_user.equals("") && !_pass.equals("") && _to.length > 0 && !_from.equals("") && !_subject.equals("") && !_body.equals("")) { Session session = Session.getInstance(props, this); DataHandler handler = new DataHandler(new ByteArrayDataSource(_body.getBytes(), "text/html")); MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(_from)); msg.setDataHandler(handler); InternetAddress[] addressTo = new InternetAddress[_to.length]; for (int i = 0; i < _to.length; i++) { addressTo[i] = new InternetAddress(_to[i]); } msg.setRecipients(MimeMessage.RecipientType.TO, addressTo); msg.setSubject(_subject); msg.setSentDate(new Date()); // setup message body BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(_body); _multipart.addBodyPart(messageBodyPart); // Put parts in message msg.setContent(_multipart); // send email Transport transport = session.getTransport("smtps"); Transport.send(msg); Log.v("mas", "Email was send"); return true; } else { Log.v("mas", "Email was not send"); return false; } } public class ByteArrayDataSource implements DataSource { private byte[] data; private String type; public ByteArrayDataSource(byte[] data, String type) { super(); = data; this.type = type; } public ByteArrayDataSource(byte[] data) { super(); = data; } public void setType(String type) { this.type = type; } public String getContentType() { if (type == null) return "application/octet-stream"; else return type; } public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(data); } public String getName() { return "ByteArrayDataSource"; } public OutputStream getOutputStream() throws IOException { throw new IOException("Not Supported"); } } @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(_user, _pass); } private Properties _setProperties() { Properties props = new Properties(); props.put("", _host); if(_debuggable) { props.put("mail.debug", "true"); } if(_auth) { props.put("mail.smtp.auth", "true"); } props.put("mail.smtp.port", _port); props.put("mail.smtp.socketFactory.port", _sport); props.put("mail.smtp.socketFactory.class", ""); props.put("mail.smtp.socketFactory.fallback", "false"); return props; } // the getters and setters public String getBody() { return _body; } public void setBody(String _body) { this._body = _body; } public void setTo(String[] toArr) { // TODO Auto-generated method stub this._to=toArr; } public void setFrom(String string) { // TODO Auto-generated method stub this._from=string; } public void setSubject(String string) { // TODO Auto-generated method stub this._subject=string; } // more of the getters and setters ….. }

notice : email body changed for every person. so i cant use :

String rec_email[] = {"email1","email2" , ....};

and use one times sendMail function, because in this case send same content to all.

where is the problem?? Please help me.

Category:android Views:6 Time:2018-09-01

Related post

  • ***.tmp is not a valid win32 resource file. How to resolve this weird bug on Visual Studio? 2009-12-21

    I use Visual Studio 2008 SP1. I'm experiencing a boring bug, that sometimes break my compilation processes with something like: Error 4 'C:\dev(...)\obj\Debug\CSC4B.tmp' is not a valid Win32 resource file (...) This file doesn't even is shown in the

  • how to resolve java result 1 errors 2010-11-20

    How to resolve 1 particular flavor of 'java result 1' in the context of using JVMTI agents? --------------Solutions------------- Here's how I resolved an issue in my context: The server is run through an ANT script with jvm configured with an agent (

  • How to configure java.util.logging on Android? 2010-12-30

    I want to use java.util.logging on Android. I want to configure the logging system with But how can I tell Android using the specific configure file? For example, I placed the in the classpath root of the applic

  • How to resolve Error executing aapt in Android/Eclipse? 2011-11-04

    This question already has an answer here: aapt not found under the right path 12 answers Error executing aapt. Please check aapt is present at /home/padmakumar/android-sdk/platform-tools/aapt NhpAndroid_tablet_k4 line 1 Android ADT Problem Hint: On 6

  • How to map java's AffineTransform to android's Matrix? 2010-08-20

    Suppose I initialize an AffineTransform as below: AffineTransform af = new AffineTransform(2, 3, 4, 5, 6, 7); How would I create an equivalent Matrix using android's sdk? --------------Solutions------------- From AffineTransform's javadoc: [ x'] [ m0

  • How to use Java annotations to guide Android's Proguard? 2010-12-16

    When using Proguard with Android, methods that are only invoked via reflection (e.g., callbacks defined in onClick XML attributes) are erroneously stripped out. One solution for this issue is to add each affected class and method to your proguard.cfg

  • how to resolve "java.lang.NoClassDefFoundError: org/apache/velocity/context/Context" 2011-08-22

    I'm a new learner of apache cxf. in the first program i implement, i encoutered the following exception( this is what my console display): Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/velocity/context/Context The java code so

  • How to resolve java.lang.ClassCastException : 2011-08-19

    I'm using some third party jar file, there are plenty of Jar files as well, and I have the code written by someone else. While executing, I'm geting this error->"java.lang.ClassCastException : org.apache.axis.client.Service cannot be cast to org.a

  • pagerank: how to resolve java.lang.StackOverflowError? 2012-04-07

    I'm trying to implement a pagerank algorithm with 1 million nodes as input. However, I've got this error. I'm quite sure it's because an open recursive call problem, from generateParamList(). I've tried to make this method a different way not using r

  • How to resolve java.nio.charset.UnmappableCharacterException in Scala 2.8.0? 2009-11-18

    I'm using Scala 2.8.0 and trying to read pipe delimited file like in code snipped below: object Main { def main(args: Array[String]) :Unit = { if (args.length > 0) { val lines ="QUICK!LRU-2009-11-15.psv") for (line <-l

  • How to resolve Java issue with multiple threads when executing with a runnable jar file? 2010-05-24

    I have developed a Java Swing application, which uses the SwingWorker class to perform some long running tasks. When the application is run from the IDE (Netbeans), I can start multiple long running tasks simultaneously without any problem. I created

  • How to Resolve USB Host Issue in Android? 2011-01-21

    I am trying to host a USB Stick to my Android Device using "USB 2.0 Type A to Mini USB 5-Pin Type B Female / Male Adapter". I have two requirements: To Trigger USB stick from my android device. To recieve Data from USB after triggering it. But Androi

  • How to resolve java.lang.NoClassDefFoundError? 2011-04-22

    I'm currently working on a simple web project, for which I am using the SDK of Polarion. When trying to work with the according *.jar-Files, Tomcat 7 throws the following error message on start-up: SCHWERWIEGEND: Exception sending context initialized

  • How to resolve this error: ClassCastException: cannot be cast to android.view.ViewGroup 2011-06-15

    If this is the wrong place to ask this question, please direct me to a more appropriate location. I am working on an Android project in Eclipse. When I attempt to view the Preference layout in graphical view, I keep getting this error: ClassCastExcep

  • How to resolve Java LinkageError Exception? 2011-08-05

    I am developing an application for WebSphere 6.0 which uses a Java servlet.After deploying and running my application, I am receiving a LinkageError of the following type (from the server log): Error 500: java.lang.LinkageError: LinkageError while de

  • How to resolve 2012-02-23

    I am getting this error: Protocol not found[java.lang.StringBuilder] When the following line is getting executed: url = new URL(urlString.toString()); urlString stores the following value:

  • how to resolve this error " cannot be resolved to a type" in android 2012-04-02

    i am creating simple call filter application which restrict unwanted calls. i use following code to restrict call but i am unable to resole problem of this line in below code " telephonyService = (ITelephony)

  • How to resolve Android class issues: android.Manifest$permission and android.R? 2010-04-05

    I have updated software and ADT in my Eclipse a number of times. I am unable to run projects above than 1.5.I have the following errors showing up in my console window after i create a HelloWorld project with API Level 4 (1.6): [2010-04-04 22:21:53 -

  • How to instruct users to report a bug in Android 2010-07-21

    How do you instruct users to report a bug in Android? Any advice or tips? I'd like to get send detailed instructions to my users to get the most of their bug report. I know there are various apps that send bug reports from the device and I was wonder

  • How to use java.awt.image package in android app 2010-08-07

    I have to use java.awt.image package for BufferedImage class in my android app, but I am not able to do this and does anyone knows that how to do this in Android or what's the equivalent class of java.awt.Image in Android? --------------Solutions----

  • How to resolve couldn't get connection factory client error on android 2010-10-26

    couldn't get connection factory client running the MapsDemo sample application on emulator. I'm getting the error: couldn't get connection factory client. How to resolve this error? --------------Solutions------------- I had reinstalled Android dev k

  • How to resolve null pointer exception during camera capture in Android 2010-12-11

    How to resolve null pointer exception that occurred when I try to use Intent.putExtra() in calling camera activity. public class ImageCaptureActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(

  • iframe is not working android inbuild browser how can resolve issue? 2012-02-08

    I am working on a cross platform mobile application using phonegap (html,javascript) problem is selected item related image not display in iframe and this image display another page please see below code <html> <head> <script> funct

  • How can I get help directly from Microsoft on resolving a confirmed bug? 2014-01-22

    How can I get help directly from Micorsoft on resolving a confirmed bug? I have tried on the Windows Live Mail Forum since June 15, 2011 to no avail. Most of the people that respond have no connection with Microsoft and tend to ridicule and insult cu

  • how to include the Skype Kit java APIs inside an android application on Ecclipse IDE? 2011-03-04

    I am working on an application where I need to integrate the Skype Java APIs inside an android application. Could some one provide any pointers? Thanks. --------------Solutions------------- You have to include the library (the .jar file) into the Bui

Copyright (C), All Rights Reserved.

processed in 0.178 (s). 11 q(s)