I need to send email automatically without having to choose email application on the emulator. Is it possible? That is, put the email subject and body of the email by default when you click a button and the email should be sent automatically.
Asked
Active
Viewed 257 times
0
-
Please go through this: http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a – Shrikant Ballal Aug 21 '13 at 15:05
1 Answers
0
You can make a php script on ur server :
<?php
$name = $_POST['name'];
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = "From: ".$name."\r\n";
$message .= $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>
and from android app send the data using json: [You can get values from edittext and use the values here]
public static void sendData(String name, String to, String from, String subject, String message)
{
String content = "";
try
{
/* Sends data through a HTTP POST request */
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://your.website.com");
List <NameValuePair> params = new ArrayList <NameValuePair>();
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("to", to));
params.add(new BasicNameValuePair("from", from));
params.add(new BasicNameValuePair("subject", subject));
params.add(new BasicNameValuePair("message", message));
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
/* Reads the server response */
HttpResponse response = httpClient.execute(httpPost);
InputStream in = response.getEntity().getContent();
StringBuffer sb = new StringBuffer();
int chr;
while ((chr = in.read()) != -1)
{
sb.append((char) chr);
}
content = sb.toString();
in.close();
/* If there is a response, display it */
if (!content.equals(""))
{
Log.i("HTTP Response", content);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}

Prakhar
- 2,270
- 19
- 26
-
Please explain, which URL should be used to post mail by using gmail or any other mail by your method? – Shrikant Ballal Aug 21 '13 at 15:06