问题
Possible Duplicate:
Sending Email in Android using JavaMail API without using the default/built-in app
I want to send an email with an attached audio file over gmail that i record with my application. Can I send a direct mail from android with attachment without getting the options to choose the method of sending? (bluetooth,etc etc ) ? I just want to send the mail with the attachment on the click of a button.
Can I do this with android? Also, i would be obliged is I could get the code for sending mail over gmail with android.
回答1:
here is a complete example which sends a background email (using gmail account) to others, ofcourse with attachment. Send email with attachment using GMAIL account.
Find an example project here
in this project you need to set the following gmail account details in MailSenderActivity
class
private static final String GMAIL_EMAIL_ID = "";
private static final String GMAIL_ACCOUNT_PASSWORD = "";
private static final String TO_ADDRESSES = ""; // to email addresses separated by comma
If you don't need the ZipUtility class, remove that and use it according to your need
回答2:
unfortunately, there is no way to force the user to choose the Gmail app instead of the built in mail client.
most users already have a gmail account if they own an android client so they'll probably use it anyway.
回答3:
As others have already posted you can use the java mail api, BUT you'd have to hardcode your email and password which isn't something advisable.
What you can do is connect to a webservice that can send emails and use it instead. That way you reduce your security risks.
来源:https://stackoverflow.com/questions/11340023/connecting-directly-to-gmail-with-android