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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:33:26+00:00 2026-05-23T14:33:26+00:00

I am new to android development . I am making a small email client

  • 0

I am new to android development . I am making a small email client using javamail api . I am not able to find a solution on how will that activity start . Below is my code file for email manager which I want to start when I run the application .

I just need a way to start this , I am really confused with the android activities and have clue how to implement them
Thanks in Advance 🙂

package com.mailtest.android;

import android.app.Activity;
import android.os.Bundle;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import android.view.View;
import android.os.Bundle;
import android.content.Intent;
import android.widget.Button;

public class EmailManager extends Activity {


    **/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);** 
    } 
    private String stmpHost = "smtp.gmail.com";
        private String mailServer = "imap.gmail.com";
        private EmailAccount account;
        private Session smtpSession; 
        private Session imapSession; 
        private Folder inbox;
        private Store store;



        public EmailManager(String username, String password, String urlServer, String stmpHost, String mailServer) {
            account = new EmailAccount(username, password, urlServer);
            this.stmpHost = stmpHost;
            this.mailServer = mailServer;
            initProtocol();
        }
        private void initProtocol() {
            EmailAuthenticator authenticator = new EmailAuthenticator(account);

            Properties props1 = new Properties();  
            props1.setProperty("mail.transport.protocol", "smtps");  
            props1.setProperty("mail.host", stmpHost);  
            props1.put("mail.smtp.auth", "true");  
            props1.put("mail.smtp.port", "465");  
            props1.put("mail.smtp.socketFactory.port", "465");  
            props1.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");  
            props1.put("mail.smtp.socketFactory.fallback", "false");  
            props1.setProperty("mail.smtp.quitwait", "false");  
            smtpSession = Session.getDefaultInstance(props1, authenticator); 

            Properties props2 = new Properties();
            props2.setProperty("mail.store.protocol", "imaps");
            props2.setProperty("mail.imaps.host", mailServer);
            props2.setProperty("mail.imaps.port", "993");
            props2.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            props2.setProperty("mail.imaps.socketFactory.fallback", "false");
            imapSession = Session.getInstance(props2);
        }   
        public Message[] getMails() throws MessagingException {
            store = imapSession.getStore("imaps");
            store.connect(mailServer, account.username, account.password);
            inbox = store.getFolder("Inbox");
            inbox.open(Folder.READ_ONLY);
            Message[] result = inbox.getMessages();

            return result;
        }
        public void close() {
            //Close connection 
            try {
                inbox.close(false);
                store.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }       
        }
        public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception {  
            MimeMessage message = new MimeMessage(smtpSession);
            DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));  
            message.setSender(new InternetAddress(sender));  
            message.setSubject(subject);  
            message.setDataHandler(handler);  
            if (recipients.indexOf(',') > 0)  
                message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));  
            else  
                message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));  
            Transport.send(message);  


            }
        } 

AND THIS IS MY MAIN.XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />

</LinearLayout>  
  • 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-23T14:33:27+00:00Added an answer on May 23, 2026 at 2:33 pm

    First of, you might want to have the email manager in its own class since it´s not a necessity to extend it as an Activity. However, to answer your question you could have a look at http://developer.android.com/reference/android/app/Activity.html

    This is just an example and let´s say that the activity that should start the other activity is called MainActivity.
    Then put this in MainActivity:

      startActivity(new Intent(MainActivity.this, EmailManager.class)); 
    

    Just remember to put the Email Manager as an Activity in your AndroidManifest.xml

    <activity android:name=".EmailManager"/>
    

    Possible duplicate answer, more can be found here: How to start activity in another application?

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

Sidebar

Related Questions

I'm new to Eclipse and I'm using for some Android development. Eclipse is making
I am still pretty new to Android development, and I have not been able
I am new to android development, making a simple game and using onKeyDown(.....) function
Extreme Android developer newbie here...well, new to Android development, not development in general. I
I am new to Android development. I am using a x-platform development tool which
I'm entirely new to Android development, and I'm interested in making a live wallpaper.
I'm very new to Android development and can't find the answer to this. I
I'm new to Android development, and I was wondering if anyone knew either how
I'm new to Android development and I'm currently going through some tutorials. When I
I'm new to Android development and working on an Android application that requires the

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.