Simple mail sender - android

Earlier I was using an intent to complete this operation:
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"xxxxxxx#gmail.com"});
email.putExtra(Intent.EXTRA_TEXT, "");
email.setType("message/rfc822");
try{
startActivity(Intent.createChooser(email, "Feedback to TFC"));
}catch(android.content.ActivityNotFoundException e)
{
Toast.makeText(getApplicationContext(), "There are no email clients installed", Toast.LENGTH_SHORT).show();
}
But then again the intent results in a form with the address, subject and the message. For now I only want the message part. I did have a look at this blog . Is it necessary to give the username and password ?? Is there no simple mailto: function in android as we see in html so that the message is just sent without me having to use the all the complicated functions ?

You can refer to https://stackoverflow.com/a/2033124/1051147 which explains how to Send e-mail in Android using the JavaMail API using Gmail authentication
note that you will need some additional jar for getting it done. As i explained the simplest method is to use intent.

Related

how can i send email from my application using registered Android email without password

I want to send some text from my application to custom email address
i need to use email which is registered on device
i try many examples which is using email and password ,or using Intent , but it's not correct for me
So how can i do this, which will looks something like this
Use below code that will ask the user to open and Email Client for sending the email -
String to = "sarkerpt#gmail.com";
String subject = "Barcode Reader For Android - Bug Report";
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));

Send mail with javamail without user and password

I followed this post Sending Email in Android using JavaMail API without using the default/built-in app to send mails without intents. it works ok. but my question is if you can send mail without having to enter your user and password? thanks
No you can't
As you can see from the code, The username and password is used to login to that mail ID and then that Email ID is used to send the Email
The GMailSender has a constructor that takes in the username and password, this is used to create a login session as in code
session = Session.getDefaultInstance(props, this);
Once the login has been done now your sending the Email from that mail ID as you normally do in browser
Alternatives
Now if you want to send a email then you can send an intent in android like this
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"youremail#gmail.com"});
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "message");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client"));
But this would pop up the user with the choice of client from which email has to be sent
OR
If you even dont want to use this, then I would suggest creating your own webserver and make HTTP request to it to send Emails via the server

Android Send Email not present in email client sent

When I try to send an email (for example with gmail client) via INTENT, in my email client I don't see the email sent. The code is:
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
email.setType("application/zip");
email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(pathZipCryptDestination)));
email.setType("message/rfc822");
activity.startActivity(Intent.createChooser(email, "E-Mail:"));
The email arrives but I don't see it in email sent.
I must set some parameter?
What client are you exactly using?
Basically all you do is pass some data to the other app, which uses this.
It has little to do with your own app, as the other app takes over and completes sending the email. If somehow they do not do this properly and thus your email is not added to your 'send emails' that sounds more like a problem in their app and out of your hands.

It is possible to hide the destination email address?

In my app I have an option, "Contact us", but anyway, I would like that the user to not see the email address where they send the email. I use the standard way to send the email, but however I build the interface, when the Email Client starts the destination email is shown.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"myemail#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
//i.putExtra(Intent.EXTRA_TEXT , "emailBody");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(SecondActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
I would like that myemail#gmail.com to be undisclosed to users.
Over the internet we find this in many cases, where just a button "Send" is provided, for example, but how could we do this on Android?
I would like that myemail#gmail.com to be undisclosed to users.
If you wish to use ACTION_SEND, the user has the right to know the content they are sending and the email address they are sending it to, and to modify any of that as they see fit. It is their device, their email account doing the sending, and their bandwidth that is being consumed.
Over the internet we find this in many cases, where just a button "Send" is provided
The Web server is sending the email, rather than asking the user's browser to send the email.
how could we do this on Android?
You are welcome to find a JavaMail port for Android, or an equivalent library, and send the email directly yourself. Of course, you will need to configure your app to know an SMTP relay that you can use to do the sending.

Email sending via Android Application

I want to send email from my application without configuration email in android device.
can we do this?? we click a button and mail will automatically to the recipient.
I have used the following code. where we can give the sender name.
and can we send mail via android emulator.
Thanx.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"abc#example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Request For Quote");
intent.putExtra(Intent.EXTRA_TEXT , "Hi....");
try {
//startActivity(Intent.createChooser(intent, "Send mail..."));
startActivity(intent);
//Toast.makeText(SendingEmailActivity.this, "Mail Sent Successfully", Toast.LENGTH_SHORT).show();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(DemoActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Check this thread
Sending Email in Android using JavaMail API without using the default/built-in app
Without any intervention, you couldn't use Intents.
Take a look at This tutorial about javamail and android

Categories

Resources