Send emails with intent in Android

Source: Internet
Author: User
Tags codepad

The following is an util class for sending emails with intent. attachments can be sent.

// Mailutil. javapackage COM. maclab. util; import Java. io. file; import COM. dropbox. client2.session. session. accesstype; import android. content. context; import android. content. intent; import android. content. sharedpreferences; import android.net. uri; public class mailutil {public static void Sendmail (string path, context c) {file = new file (PATH); // The attachment file address intent = new intent (intent. action_send); intent. putextra ("subject", file. getname (); // intent. putextra ("body", "email from codepad"); // body intent. putextra (intent. extra_stream, Uri. fromfile (File); // Add an attachment. the attachment is the file object if (file. getname (). endswith (". GZ ") {intent. settype ("application/X-gzip"); // If GZ is used, use the mime of gzip} else if (file. getname (). endswith (". TXT ") {intent. settype ("text/plain"); // for plain text, use the mime of text/plain} else {intent. settype ("application/octet-stream"); // other types Use stream as binary data.} C. startactivity (intent); // call the system's mail client to send} public static void mailcontact (context c, string mailadress) {intent it = new intent (intent. action_send); string [] receiver er; receiver ER = new string [] {mailadress}; it. putextra (intent. extra_email, receiver); it. putextra ("subject", "about codepad"); it. putextra (intent. extra_text, "/* thanks advance for any tips. */"); it. settype ("text/plain"); C. startactivity (intent. createchooser (IT, "Choose email client"); // call the system's mail client to send }}

Because it is a static method, you can directly call it. Call results:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.