How to send a batch with emails in android? - android

I want to send several emails to different recipients, but the text of the letters may differ. And I also want to authorize the user and send mail on his behalf, by Intent and the built-in mail client app. And is there any way to do this with one button click, rather than calling up a new email window (activity) for each of these letters and forcing the user to confirms the sending of each letter?
And is there any way to not call the new e-mail window for each of these letters, so that the user confirms the sending of each letter, and do this at the touch of a button?
Maybe are there any third-party libraries or free mail services for this purpose?

You can use simple-java-mail to achieve that.
public static void SendMail(String recipientName,String recipientAddress,String subject,String message,File file,String myAdress,String password) throws IOException{
System.out.println("File size "+file.length());
Email email = new Email();
email.setFromAddress(myAdress.split("#")[0], myAdress);
email.addRecipient(recipientName, recipientAddress, Message.RecipientType.TO);
email.setSubject(subject);
email.setText(message);
if(file!=null)
email.addAttachment(file.getName(),
FileUtils.readFileToByteArray(file),"application/pdf");
String host = myAdress.split("#")[1];
new Mailer(
new ServerConfig("smtp."+host, 587, myAdress, password),
TransportStrategy.SMTP_TLS,
new ProxyConfig("socksproxy."+host, 1080, "proxy user", "proxy password")
).sendMail(email);
}
If your client is using Gmail, they have to allow third parties to send mail in their settings

Related

How to receive email from system, using Intent Filter?

I searched for the query online and figured the intent-filter in the AndroidManifest.xml file. However, I am still unable to find how to receive the clicked email id in my application.
My problem
Suppose I receive a message on my WhatsApp chat box containing an email id (xyz#test.com).
On clicking the email id (xyz#test.com), I want my app to open. (Figured, using Intent-filter)
Upon opening my application, I want the email id (xyz#test.com) to be automatically copied into the EditText on my activity.
I have tried with the following function:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String x = intent.getExtras().getString(Intent.EXTRA_EMAIL);
Toast.makeText(MainActivity.this, x, Toast.LENGTH_SHORT).show();
}
*Toast is for checking whether string is being received or no.
However, the toast appears empty,showing that the string is not getting received.
I believe that the email intent is really designed for sending/composing an email, not for copying data from the email into your application. See here:
http://developer.android.com/guide/components/intents-common.html#Email
If you wanted to get an email address for someone, you may want to try the contacts intent instead:
http://developer.android.com/guide/components/intents-common.html#Contacts
If an app invokes your activity via an ACTION_VIEW Intent, there is no documented means for that app to give you an email address.
If an app invokes your activity via an ACTION_SENDTO Intent, the email address will be in the Uri. That Uri scheme should be mailto: (as that what your filter is restricting it to). I think you get the address via getSchemeSpecificPart() on the Uri, though I have not tried this.
Note that there is no requirement for an app to launch any third-party activity when the user clicks an email address, let alone one of the two that you that you have set up via the <intent-filter>.

How to send MMS without prompting to send it via gmail ,whatsapp or something else ?

When I am Using this code to send mms to specific user it shows me popup to send it via gmail,whatsapp,gtalk,message and etc. But in my case I just want to send that image as an mms to specific number that i will define in address field whithout showing any popup can any body tell me How to do this ? I googled for this and find lot of stuff on it.
Here is my code*strong text*
public void sendData(int num){
String fileString = "..."; //put the location of the file here
Intent mmsIntent = new Intent(Intent.ACTION_SEND);
mmsIntent.putExtra("sms_body", "text");
mmsIntent.putExtra("address", num);
mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileString)));
msIntent.setType("image/jpeg");
startActivity(Intent.createChooser(mmsIntent, "Send"));
}
Using an intent (like you did) is the preferred way because it's easy to implement and let the user choose his favorite app for the task of sending the MMS.
That being said you can still implement yourself the operation and send the MMS programmatically from your app by crafting and sending the appropriate HTTP request.
The following answer will provide you all the information you need: How to send image via MMS in Android?

Sending Email from EditText in Android App

I'm having an issue similar to this: Adding text from edit text field into an email . I am able to do what this is doing, but how could I send the email straight from a submit button, instead of having it compose an email in a default email client. This should be able to be sent with as anonymous and not need to be sent by default from an installed email client.
You need to download JavaMail API:
Download: https://java.net/projects/javamail/pages/Home
You need an SMTP server, also username and password for auth.
String host="your smtp";
final String user="from email address";//change accordingly
final String password="frm email password";//change accordingly
String to="to email";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", "true");
javax.mail.Session session = javax.mail.Session.getDefaultInstance(props,new javax.mail.Authenticator() {
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(user,password);
}
});
//Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(javax.mail.Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("javatpoint");
message.setText("This is simple program of sending email using JavaMail API");
//send the message
javax.mail.Transport.send(message);
System.out.println("message sent successfully...");
}
catch (MessagingException e)
{
e.printStackTrace();
}
There is no way to send an email silently, without either
letting the user know and accept it first (by using intents and an email provider)
or asking for the username and password before and using an email API as above (the user will implicitly give you the approval to send/receive emails by entering those values)
And that is a very good thing! There are too many security concerns otherwise. If you ever find a way, please post it as a bug report in android.
Workaround:
You need to use an email API such as JavaMail:
Sending Email in Android using JavaMail API without using the default/built-in app
There are some anonymous mailers that have APIs that you could use. But I would suggest you not do this. I actually agree with #DheeB 100%. I can't up vote yet.
Here is an example of one such service: http://api.temp-mail.ru/ It's in Russian but it can be translated. Again, I don't recommend but trying to answer your question.

send data to email in background

I am working on sending my message data on my email Id.I have made a mainActivity class containing an editText (for emailId) and a Button.
Another class is BroadcastReceiver class in which I retrieve data.
Now I can't understand how to send that data to the provided email in Background.
I have googled a lot but can't get the required response.
Please share the ideas and help me in it.
I create open source library for this. Usage is very simple:
BackgroundMail bm = new BackgroundMail(context);
bm.setGmailUserName("yourgmail#gmail.com");
bm.setGmailPassword("yourgmailpassword");
bm.setMailTo("receiver#gmail.com");
bm.setFormSubject("Subject");
bm.setFormBody("Body");
bm.send();
With this permissions
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
You can download it here:
https://github.com/kristijandraca/BackgroundMailLibrary
In android, You can send Email with explicit email intent however it will show a email screen and will not allow to send data in background.
To send data in background, you can use java mail api to send the mail.
Take a look on this http://www.tutorialspoint.com/java/java_sending_email.htm
This is one way of sending emails by using explicit email intent but this will not send in background
Intent sendemai = new Intent(Intent.ACTION_SEND);
sendemai.putExtra(Intent.EXTRA_EMAIL,
new String[] { toaddress });
sendemai.putExtra(Intent.EXTRA_CC,
new String[] { emailadd });
sendemai.putExtra(Intent.EXTRA_SUBJECT, sub);
sendemai.putExtra(Intent.EXTRA_TEXT, body);
// need this to prompts email client only
sendemai.setType("message/rfc822");
startActivity(Intent.createChooser(payment_request,
"Select email application"));
If you want to send in background then you need to provide some of user secure credentials.See Here

Action Intent for Gmail in android?

I am creating an app in which user can share "something" by clicking on a share button.
The steps to share "something" are:
On clicking the share button the contact list should open
By selecting a contact (with valid a email address) the data should be sent directly to the selected contact from the sender's default email address(Gmail) without popping up a window for selecting an email client like "Gmail", "Dropbox" etc..
I managed to get the email id of contact with the help of
http://mobile.tutsplus.com/tutorials/android/android-essentials-using-the-contact-picker/
but after selecting a contact I get a pop up for selecting an email client like "Gmail", "Dropbox" etc..
here is my code so far
if( email.length() != 0 )
{
Intent sharingIntent = new Intent(
android.content.Intent.ACTION_SEND );
sharingIntent.setType("message/rfc822");
String shareBody =
"Hey buddy listen to this station it is awesome\n"
+ mNowPlayingSong.mAudioUrl;
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"I liked this song" );
sharingIntent.putExtra(
android.content.Intent.EXTRA_TEXT, shareBody );
String emailAddressList[] = {email};
sharingIntent.putExtra(Intent.EXTRA_EMAIL, emailAddressList );
startActivity( sharingIntent );
You cannot send email silently with the default application. You can only create an intent that will call an activity and that will fill in all the fields.
Other possibility is to embed your own email client into yours application. In this case, if a user provides credentials then you'll have a possibility to send a email silently. To implement the second options check this:
Sending Email in Android using JavaMail API without using the default/built-in app

Categories

Resources