How can I send emails with attachments in the Android system? In fact, intent can easily send emails, which only takes 10 lines. Code Here, Android development network uses the android123.cwj file on sdcard as an example to send an email through intent. The complete code is as follows:
File file = new file ("\ sdcard \ android123.cwj"); // attachment file address
Intent intent = new intent (intent. action_send );
Intent. putextra ("subject", file. getname ());//
Intent. putextra ("body", "android123-email sender"); // body
Intent. putextra (intent. extra_stream, Uri. fromfile (File); // Add an attachment. the attachment is a file object.
If (file. getname (). endswith (". GZ ")){
Intent. settype ("application/X-gzip"); // if it is GZ, use the gzip mime
} Else if (file. getname (). endswith (". txt ")){
Intent. settype ("text/plain"); // mime of text/plain is used for plain text.
} Else {
Intent. settype ("application/octet-stream"); // all others use stream as binary data for sending
}
Startactivity (intent); // call the system's mail client to send