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 8847999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:19:25+00:00 2026-06-14T12:19:25+00:00

I’m creating an android application which needs to send e-mail to a specific mail

  • 0

I’m creating an android application which needs to send e-mail to a specific mail id. I tried using intent (ACTION_SEND).Since it requires user interaction i didn’t use this method. what i want is to send the e-mail through back end(without the knowledge of user). Can anyone tell me the best suited way? Thanks in advance…

  • 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-06-14T12:19:26+00:00Added an answer on June 14, 2026 at 12:19 pm

    Use this class to send email.
    create an object of this class with username and password as arguments.

    public class MailSender {
    private String mailhost = "smtp.gmail.com";
    private String user;
    private String password;
    private Session session;
    private Multipart _multipart;
    public BodyPart messageBodyPart;
    DataSource source;
    static {
        Security.addProvider(new com.PackageName.JSSEProvider());
    }
    
    public MailSender(String user, String password) {
        this.user = user;
        this.password = password;
    
        Properties props = new Properties();
        props.setProperty("mail.transport.protocol", "smtp");
        props.setProperty("mail.smtp.host", mailhost);
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.socketFactory.fallback", "false");
        props.setProperty("mail.smtp.quitwait", "false");
        _multipart = new MimeMultipart();
        session = Session.getInstance(props, new MailAuthenticator(user,
                password));
    
    }
    
    public synchronized void sendMail(final String subject, final String uuid,
            final String address, final double latitude,
            final double longitude, final String recipients,
            final String filepath, final Context context, final int i, final int j)
            throws Exception {
    
        Thread thread = new Thread() {
            public void run() {
                Looper.prepare();
                try {
                    System.out.println("SENDING       MAIL");
                    Message message = new MimeMessage(session);
                    messageBodyPart = new MimeBodyPart();
                    DatabaseAdapter db = new DatabaseAdapter(context);
                    String eId = db.getYourId();
                    message.setFrom(new InternetAddress(eId));
                    message.setSubject(subject);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    String currentDate = sdf.format(new Date());
                    SimpleDateFormat sTf = new SimpleDateFormat("hh:mm:ss");
                    String currentTime = sTf.format(new Date());
                    System.out.println(i);
                    messageBodyPart
                            .setText("Someone tried to unlock your device(ID : "+uuid+" ) at: "
                                    + currentTime + " on " + currentDate + "\n"
                                    + "Device Location : " + address + "\n"
                                    + "Map: " + "http://maps.google.com/?q="
                                    + latitude + "," + longitude);
                    if (recipients.indexOf(',') > 0)
                        message.setRecipients(Message.RecipientType.TO,
                                InternetAddress.parse(recipients));
                    else
                        message.setRecipient(Message.RecipientType.TO,
                                new InternetAddress(recipients));
    
                    Transport transport = session.getTransport("smtp");
                    System.out.println("CONECTING.....");
                    transport.connect(mailhost, user, password);
                    message.saveChanges();
                    message.setContent(_multipart);
                    _multipart.addBodyPart(messageBodyPart);
                    message.setContent(_multipart);
                    if (source != null) {
    
                        message.setFileName("image");
                    }
                    Transport.send(message);
                    System.out.println("Mail  sent ...");
    
                    }
    
                    transport.close();
    
    
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
            }
        };
        thread.start();
    
    }
    
    public void addAttachment(String filename) throws Exception {
        if (!filename.equals("")) {
            System.out.println("Ataching     file        :)");
            messageBodyPart = new MimeBodyPart();
            source = new FileDataSource(filename);
            messageBodyPart.setDataHandler(new DataHandler(source));
            messageBodyPart.setFileName(filename);
            _multipart.addBodyPart(messageBodyPart);
            System.out.println("FILE    ATTACHED        :)");
        }
    }
    
    
    class MailAuthenticator extends Authenticator {
        String us;
        String pw;
    
        public MailAuthenticator(String username, String password) {
            super();
            this.us = username;
            this.pw = password;
        }
    
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(us, pw);
        }
    }
    

    }

    Also add this in other file.

    public final class JSSEProvider extends Provider {
    private static final long serialVersionUID = 1L;
    
    public JSSEProvider() {
        super("HarmonyJSSE", 1.0, "Harmony JSSE Provider");
        AccessController
                .doPrivileged(new java.security.PrivilegedAction<Void>() {
                    public Void run() {
                        put("SSLContext.TLS",
                                "org.apache.harmony.xnet.provider.jsse.SSLContextImpl");
                        put("Alg.Alias.SSLContext.TLSv1", "TLS");
                        put("KeyManagerFactory.X509",
                                "org.apache.harmony.xnet.provider.jsse.KeyManagerFactoryImpl");
                        put("TrustManagerFactory.X509",
                                "org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl");
                        return null;
                    }
                });
    }
    

    }

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.