+ 1

Android code to send email directly

Hello. How to send email directly from the android app to the recipient’s email? Not using intent and no need for Google Compose window opening. Please let me know about it ASAP.

14th Sep 2018, 8:50 AM
Srijana KC
Srijana KC - avatar
5 Respostas
0
You can send email directly from code: String to = "abcd@gmail.com"; String from = "web@gmail.com"; Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", SMPT_HOSTNAME); Session session = Session.getInstance(properties, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(USERNAME, PASSWORD); } }); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress( to)); message.setSubject("This is the Subject Line!"); message.setText("This is actual message"); Transport.send(message); System.out.println("Sent message successfully...."); } catch (MessagingException mex) { mex.printStackTrace(); } I hope this will be helpful!!!
14th Sep 2018, 11:43 AM
Manu Pandey
Manu Pandey - avatar
0
I need that all users who download the app can send email. How to know their email address?
14th Sep 2018, 11:45 AM
Srijana KC
Srijana KC - avatar
0
thanks a lot for the code Manu Pandey
14th Sep 2018, 11:47 AM
Srijana KC
Srijana KC - avatar
0
There are many apps present on Google playstore like "Boomerang Gmail" which allows you to exchange emails easily. To find someone's email address you can check out some steps here: https://www.yesware.com/blog/find-email-addresses/ I hope this will give you your answer!!
14th Sep 2018, 12:09 PM
Manu Pandey
Manu Pandey - avatar
0
l mean in the above code of yours, how to make String from the same user who has downloaded this app of mine and sends email to String to email which I assign
14th Sep 2018, 12:13 PM
Srijana KC
Srijana KC - avatar