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.
Related
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
I need to be able to check if the user has sent the text I set in my code;
Intent messageIntent = new Intent(Intent.ACTION_SEND)
messageIntent.putExtra(Intent.EXTRA_TEXT, "Text I want to send");
or has changed the prefixed text (on the SMS client app, email client app, or the app that gets launched by the intent) before sending it.
I need to know this because sharing my game link will give a reward to the user, so I need to check if that link is correctly shared.
I would appreciate any answer that could help.
Thanks.
ACTION_SEND isn't documented to return a result. So starting the intent with startActivityForResult() will return the default result: RESULT_CANCELED. That is, unless the receiving app has implemented support for returning a result; which is highly unlikely because it's not part of the documented behavior.
In summary, what you want to do is not possible with any of the common Intents.
You can try this...
String message = "Your Message";
intent.putExtra("IDENTIFIER", message);
And where you are going to receive the message...
String messageReceived = getIntent().getExtras().get("IDENTIFIER").toString();
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?
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
i am integrating the twitter in to my android application. and it logins me successfully on twitter but i do not know how to get the tweets and statuses from that so i can show it in my application. here is my code.
String CONSUMER_KEY = "XXXXXXXXXXXXXXX";
String CONSUMER_SECRET = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
try {
twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
String url = requestToken.getAuthorizationURL();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
catch (TwitterException e){
e.printStackTrace();
}
any help will be appreciated.
You can handle the login part, without the user introducing the pin if you use signpost, and once you have the token and the verifier, you can go on with twitter4j, creating the object twitter with TwitterFactory twitterfact=new TwitterFactory();
twitter = twitterfact.getOAuthAuthorizedInstance(consumerKey, consumerSecret,accessToken);
Now you can show the timeline with twitter.getFriendsTimeLine(). It's what I do, and it works fine. I can tweet, read tweets, send private messages... and the login part doesn't fail.
As soon as you have the twitter variable correctly populated (i.e. your code throws no Exception), you can use it to twitter.getHomeTImeline() etc.
Having said that, your code looks like it only does the first part of the OAuth procedure and that you still need to have code that sets the pin the user receives and then creates a fully OAuth authorized connection.
Have e.g. a look at LoginActivity of Zwitscher (v0.65 tag).
The method getPinButton() is basically what you have above. When the user comes back, he enters the pin in an EditText and clicks on the [setPinButton()][2] which provides the 2nd part of the OAuth stuff.
OAuth keyes and tokens are then stored in preferences for later use (you need them to create authenticated Twitter instances via the TwitterFactory (see e.g. TwitterHelper.getTwitter() on how to do this).