Send email automatically androidStudio

0

I have this code, which allows me to send an email with an attachmen of an .html

    public void clickbutton(View v) {
try {
strFile = strFile + "/report.html";

File file = new File(strFile);
if (!file.exists())
file.mkdirs();
strFile = strFile + "/report.html";
createFile();

final Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
//
address = "[email protected]";
subject = "Pruebas de correo";
emailtext = "Envio de video";
//
emailIntent.setType("plain/text");

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { address });

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://" + strFile));

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext);

this.startActivity(Intent
.createChooser(emailIntent, "Enviando Correo..."));

} catch (Throwable t) {
Toast.makeText(this, "Requerimiento Fallido: " + t.toString(),
Toast.LENGTH_LONG).show();
}
}

This is the method that creates the html

    private void createFile() {
    try {
    String data = "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/><html><body style='tab-interval: .5in'><div class="Section1"><div>";
    data += "<p class="MsoNormal" dir="LTR" style="text-align: left; unicode-bidi: embed"><span lang="AR-EG">";
    FileOutputStream fos = new FileOutputStream(strFile);

    Writer out = new OutputStreamWriter(fos, "UTF-8");

    data += "Email data" + "<br />";
    data += "bla bla bla" + "<br />";
    data += "Footer" + "<br />";

    data += "</span></p></div></body></html>";
    out.write(data);
    out.flush();
    out.close();

    } catch (Throwable t) {
    Toast.makeText(this, "Request failed: " + t.toString(),
    Toast.LENGTH_LONG).show();
    }

}

My problem is that when I press my send button, first it asks me with which application I want to send the mail, understand gmail, hotmail, drive etc and second, if I choose gmail, for example, it sends me to the window where it is created mail and I have to press send to complete the entire process ... I would like to know how I can do all this automatically, with the click of the button, the shipment is executed. It does not matter which message is sent, what I need is that I send an email. If any, it is by gmail.

    
asked by Jesus Alfredo 10.10.2018 в 15:25
source

0 answers