Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:11:06+00:00 2026-05-28T20:11:06+00:00

I have used JavaMail-android libraries to send mail in background .In order to free

  • 0

I have used JavaMail-android libraries to send mail in background .In order to free user from username and password I decided to use Auth token generated when adding an account /configuring account in android phone .So can i get the token and how could i use the token to send mail in background as a did using smtp (javamail-android) libraries .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:11:09+00:00Added an answer on May 28, 2026 at 8:11 pm

    Hi its so simple and easy call your email sending class through Service it will work automatically email will send on particular time.

    Here i have posted sample code:
    you should write code in service as GMailSender sender = new GMailSender(send_id,send_pass,imgpath);
    its for sending email through your gmail id only.

    and now GmailSender.java as follows:

    public class GMailSender extends javax.mail.Authenticator 
    

    {

    private String mailhost = "smtp.gmail.com";   
    private String user;   
    private String password;   
    private Session session;   
    private String path_img;  
    
    static {   
        // AppLogger.LogError("Reached to Step1.1");
        Security.addProvider(new JSSEProvider());   
    }  
    
    public GMailSender(String user, String password,String path) 
    {  
        path_img = path;
        // AppLogger.LogError("Reached to Step1.2");
        this.user = user;   
        this.password = password;   
    
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");
    
    
        //AppLogger.LogError("Reached to Step1.3");
        session = Session.getDefaultInstance(props, this);   
        //AppLogger.LogError("Reached to Step1.4");
    }   
    
    
    
    
    
    protected PasswordAuthentication getPasswordAuthentication() {   
        return new PasswordAuthentication(user, password);
    }   
    
    public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception {   
        try{
    
        //   AppLogger.LogError("Reached to Step1.5");
        MimeMessage message = new MimeMessage(session); 
       // AppLogger.LogError("Reached to Step1.6");
        DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/html"));   
        message.setSender(new InternetAddress(sender));   
        message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(recipients));
        //AppLogger.LogError("Reached to Step1.7");
        message.setSubject(subject);   
    
        message.setDataHandler(handler);  
    
        MimeMultipart multipart = new MimeMultipart("related");
        String htmlText=null;
    
        BodyPart messageBodyPart = new MimeBodyPart();
        htmlText = body+ "";
    
        messageBodyPart.setContent(htmlText, "text/html");
    
    
    
        MimeBodyPart attachmentPart = new MimeBodyPart();
        FileDataSource fileDataSource = new FileDataSource(path_img) {
            @Override
            public String getContentType() {
                return "image/jpg";
            }
        };
        attachmentPart.setDataHandler(new DataHandler(fileDataSource));
        attachmentPart.setFileName("image.jpg");
    
        multipart.addBodyPart(messageBodyPart);
       multipart.addBodyPart(attachmentPart);
    
        message.setContent(multipart);
    
        //AppLogger.LogError("Reached to Step1.8");
        if (recipients.indexOf(',') > 0)   
        {
            //AppLogger.LogError("Reached to Step1.9");
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));   
            Transport.send(message); 
          //  AppLogger.LogError("Reached to Step2.1");
        }
        else 
        {
            //AppLogger.LogError("Reached to Step2.2");
            message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));  
            Transport.send(message); 
        //AppLogger.LogError("Reached to Step2.3");
        }
       // Transport.send(message); 
       // AppLogger.LogError("Reached to Step2.4");
        }catch (Exception e)
        {
            throw new FileNotFoundException();
          }
    
    
    
    
    
    }   
    
    public class ByteArrayDataSource implements DataSource {   
        private byte[] data;   
        private String type;   
    
        public ByteArrayDataSource(byte[] data, String type) {   
            super();   
            this.data = data;   
            this.type = type;   
        }   
    
        public ByteArrayDataSource(byte[] data) {   
            super();   
            this.data = 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");   
        }   
    }   
    

    try this sample and try for all email ids. and make sure that you have import all libraries needed..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the script from batch file which asks for username/password + registration
I have used java mail(com.sun.mail.smtp) from my struts project. Mail is sent successfully but
I am using JavaMail to read mail in my Android app. I have tried
I have used several looking glass tools from servers around the world. What I'm
I have used this command to send xml files to a web service named
I have used Quartz.Net for queuing and sending emails from my application. I don't
I have used the ddlgen tool to export the database schemas from my DEV
I have used the code below to run cmd commands from java (code adopted
I have used the jquery ajax for getting the values from the server.when the
I have used the code available from http://codeblitz.wordpress.com/2009/06/22/jquery-charts/ It uses jqPlot. So I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.