0

Answer Found: How to send email in background in Android ?

I'm working on an android app and one of the features requested is the ability to sign up for a news letter, which is simply sending a name and an email address. The client however does not have a server to host an application to receive this information and I would like to do it without sending it as an email. I'd like it just to say "You've successfully signed up for our newsletter" or something along those lines.

Is there anyway I can do this? If so, example code would be appreciated as my background is in C# and I'm working in Java.

Edit: Even sending a hidden e-mail without asking the client to login would be acceptable.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Eidenai
  • 401
  • 6
  • 18
  • This is a bit vague. You're trying to have a notification bounce back to the app to verify they've been registered? If there's no server, where is it supposed to bounce back from? – nukeforum Sep 14 '15 at 20:24
  • Yeah, I'm aware there's no server to contact. That's why I'm asking if I can do it without one. Even sending an e-mail without asking the user to sign in would be acceptable. – Eidenai Sep 14 '15 at 20:27
  • How is the person being registered for anything if no server is being contacted? – nukeforum Sep 14 '15 at 20:31
  • Again, I am aware of the problems involved with not having a server to contact. Which is why I'm asking if anyone knows a way around it. Your questions are redundant. – Eidenai Sep 14 '15 at 20:38
  • 1
    I authored an answer for what I think you're looking for, but your question doesn't lend to fixing the problem of registering them for anything. If there is no server, there is no service. What are they registering for? A newsletter? What distributes the newsletter? How does your client receive the notification that the customer has registered? My questions are redundant because there is a lack of information that I'm trying to indicate you need in order to get your question answered the way you're expecting it to be. – nukeforum Sep 14 '15 at 20:41
  • I've been reading a bit more and it seems like maybe your client doesn't have the server information _yet_. That's fine. The `Toast` method should get your the on-screen message you're looking for. Sorry for the confusion. – nukeforum Sep 14 '15 at 20:46
  • Please read the response I've made. You can of course use Toast instead of creating a new intent to take the user to the activity, but I think you should clearly state that user is signed up and show next steps they can take after signing up with Thank you message. – Saehun Sean Oh Sep 14 '15 at 20:51
  • @nukeforum I also up-voted your comment because I may have not explained myself fully. Please see above comment about sending e-mail that is 'hidden' – Eidenai Sep 14 '15 at 20:58
  • Found answer here: http://stackoverflow.com/questions/19947685/how-to-send-email-in-background-in-android – Eidenai Sep 14 '15 at 21:13

3 Answers3

0

I think the notification method you might be looking for is Toasts. However, the validation of whether the customer has been registered will have to occur elsewhere.

Example:

Toast toast = Toast.makeText(getApplicationContext(), "You've successfully signed up for out newsletter", Toast.LENGTH_LONG);
toast.show();
nukeforum
  • 1,284
  • 3
  • 16
  • 38
0

It looks like you just want to display the message locally without server for demo purpose, right?

Well first of all, I don't really think you should learn Android in C# because of many reasons. First of all, you need Java to do Android development.

Here the simple scenario.

You have one activity called MainActivity where you have two text boxes called name and email.

You will now have a button called submit

Once user enters the name and email address and presses Submit button, it will take the user to a new activity called WelcomeActivity.

In android, you need an xml file that sets up the layout of your activity. I'll call this activity_email.xml.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.maxphone.LoginActivity">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Signup for email"
    android:id="@+id/welcomeTextView"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_marginStart="40dp"
    android:layout_marginTop="20dp" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/welcomeTextView"
    android:layout_marginTop="15dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Name"
        android:id="@+id/usrnameTextView"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/userEditText"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:maxLines="1"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Email Address"
        android:id="@+id/emailTextView"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/emailEditText"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:focusableInTouchMode="true"
        android:maxLines="1"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/email_signed_up_smg"
        android:id="@+id/loginErrorMsg"
        android:layout_gravity="center_horizontal|end"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="10dp"
        android:singleLine="false"
        android:textColor="#ffff0000"
        android:visibility="invisible" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Login"
        android:id="@+id/signupConfirmBtn"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="40dp" />

</LinearLayout>


</RelativeLayout>

Now in your MainActivity,

public class MainActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.activity_login);

    TextView txt = (TextView) findViewById(R.id.welcomeTextView);
    txt.setTextSize(40);

    final EditText usrname = (EditText) findViewById(R.id.userEditText);
    final EditText email = (EditText) findViewById(R.id.emailEditText);

    final TextView errorMsg = (TextView) findViewById(R.id.emailConfirmMsg);

    final Button submitBtn = (Button) findViewById(R.id.emailConfirmBtn);

    // Login Up button behavior
    submitBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Staring MainActivity
            Intent i = new Intent(getApplicationContext(), WelcomeActivity.class);
            startActivity(i);
            finish();
        }
    }
}
}

This class will display the Views (such as text views, edit texts, etc) and listen to user behavior. Once submitBtn is clicked, it will create an Intent (please do a research) and take the user to a new activity that intent defined.

and you can do similar work for WelcomeActivity to display welcome messages like Thank you for signing up! and such.

This is all locally done and does not need any kind of web activity. So this is basically for demo purpose.

Good luck!

Saehun Sean Oh
  • 2,103
  • 1
  • 21
  • 41
0

I found the answer here, unfortunately it requires the hard coding of an e-mail and password which is highly insecure. I will have to make more considerations.

How to send email in background in Android ?

Community
  • 1
  • 1
Eidenai
  • 401
  • 6
  • 18