通过Gmail发送邮件

 

private EditText mEditText01;
	private EditText mEditText02;
	private EditText mEditText03;
	private EditText mEditText04;
	private Button mButton01;
	private String[] strEmailReciver;
	private String strEmailSubject;
	private String[] strEmailCc;
	private String strEmailBody;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.email);

		mButton01 = (Button) findViewById(R.id.myButton1);
		mEditText01 = (EditText) findViewById(R.id.myEditText1);
		mEditText02 = (EditText) findViewById(R.id.myEditText2);
		mEditText03 = (EditText) findViewById(R.id.myEditText3);
		mEditText04 = (EditText) findViewById(R.id.myEditText4);

		mButton01.setOnClickListener(new Button.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				/* 透过Intent来发送邮件 */
				Intent mEmailIntent = new Intent(
						android.content.Intent.ACTION_SEND);
				/* 设定邮件格式为plain/text */
				mEmailIntent.setType("plain/text");
				/* 取得EditText01,02,03,04的值作为收件人地址,附件,主题,内容 */
				strEmailReciver = new String[] { mEditText01.getText()
						.toString() };
				strEmailCc = new String[] { mEditText02.getText().toString() };
				strEmailSubject = mEditText03.getText().toString();
				strEmailBody = mEditText04.getText().toString();
				/* 将取得的字符串放入mEmailIntent中 */
				mEmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
						strEmailReciver);
				mEmailIntent.putExtra(android.content.Intent.EXTRA_CC,
						strEmailCc);
				mEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
						strEmailSubject);
				mEmailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
						strEmailBody);
				/* 开启Gmail 并将相关参数传入 */
				startActivity(Intent.createChooser(mEmailIntent, "发信中..."));
			}
		});
	}
 



 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值