Yanshof
Yanshof

Reputation: 9926

Why sending mail is not working on my code ?

Trying to send mail with attached file - and i don't know why this code is not working .. the mail is not sending

public void SendMailWithAttached(String fileToSend, String mailToSend)
{  
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("vnd.android.cursor.dir/email");
    sharingIntent.putExtra(Intent.EXTRA_EMAIL, fileToSend);
    sharingIntent.putExtra(Intent.EXTRA_STREAM,mailToSend);
    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");

    startActivity(Intent.createChooser(sharingIntent, "Send email"));

}

Upvotes: 0

Views: 55

Answers (1)

Rick Falck
Rick Falck

Reputation: 1778

Here is what I do to send a file as an attachment:

File effFile = new File(toPath, files[0]);
Uri effU = Uri.fromFile(effFile);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_STREAM, effU);
startActivity(Intent.createChooser(i, "Email:"));

The i.setType("text/plain"); command didn't work when I tried others.

Upvotes: 1

Related Questions