关于android邮件的收发

Android平台邮件收发软件开发实战 本章介绍Android平台下邮件系统的整体架构,包括邮件收发的基本流程、涉及的核心组件以及与邮件服务器之间的通信机制。通过对系统架构的全面解析,为后续深入开发和调试打下坚实基础。Android邮件系统的核心流程可分为邮件发送和接收两个部分,其底层依赖于标准邮件协议(如SMTP、IMAP、POP3)与邮件服务器进行交互。系统中通常涉及以下几个关键组件:邮件客户端(Mail Client):负责用户界面交互与邮件内容处理。协议处理器(Protocol Handler) 阅读详情

讲到android的邮件收发,首先就要讲讲关于邮件协议的一下基础,度娘基本都有,这里是怕自己忘记,贴点备忘录。

 

现在常用的电子邮件协议有SMTP(25)、POP3(110)、IMAP4(143)。他们都处于TCP/IP协议簇,还包括他们的加密协议,SMTPS(465)、POPS(995)、IMAPS(993),他们的默认端口号都在后面的小括号里面了。其中的细节就不讲了,SMTP协议负责发送邮件,而POP3及IMAP4协议则负责接收邮箱里面的邮件,而IMAP协议则是一种优于POP的新协议,他克服了POP的一些缺点。例如,他可以决定客户端请求邮件服务器提交所受到邮件的方式,请求邮件服务器只下载所选中的这个邮件等。他可以使用户很好的在服务器上管理自己的邮箱,完成这些工作也不需要把邮件从服务器上下载下来。其中还牵扯到了另一个协议(MIME),在里面定义了传输邮件的邮件体内部协议。

 

首先在编写代码时需要导入JAR包:http://download.youkuaiyun.com/detail/github_34437042/9597713(其中有个bcprov的包是用来接受加密类型的)。

 

1.发送邮件

在发送邮件上并没有太大的问题,因为给出的协议就一种。在发送邮件之前需要先进行设置服务器主机,用户验证,登陆账号,创建会话并得到邮件发送对象。

 

                // 系统属性
		Properties properties = System.getProperties();

		// 设置主机
		properties.put("mail.smtp.host", "发件服务器");

		// 身份确认
		properties.put("mail.smtp.auth", "true");

		// 用户名,密码登陆
		PopupAuthenticator popupAuthenticator = new PopupAuthenticator();

		// 得到邮件回话对象
		Session session = Session.getDefaultInstance(properties, popupAuthenticator);

		session.setDebug(true);

		// 得到邮件对象
		Message message = new MimeMessage(session);

 

其中需要登陆账户:

 

public class PopupAuthenticator extends Authenticator {

	@Override
	protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication("你的邮箱账户", "你的邮箱密码");
	}

}

 

 

 

 

 

 

在整个确认用户的过程中都是异步运行,所以要进行特殊处理。完成上面的代码之后就可以往message邮件中添加自己想放的数据作为一个邮件发送出去就行了,但是在发送之前我们需要知道发送数据的几种类型(只有邮件主要内容)要特殊处理。虽然现在你可能发现在自己的message后面可以setText()发送自己想要发送的主体内容了。

 

:

以上是邮件发送及接受都需要知道的几个特殊类:Message(这是javamail中的类,不是os中的)、InternetAddress(发件人,收件人,抄送人,好像还有一个密送人都放在这些属于自己的该类数组)、Multiple(一个数据容器)、BodyPart(存放各种数据的对象容器)。就像图片中看到的内容一样,邮件的内容是层层包裹后发送的,当然这只是其中发送数据的一种方式,称之为"multipart/*"的复杂体邮件,这类邮件中可以存放附件。这些类型的分类在接收并解析邮件内容时才还会详解。因为我们不需要知道发送的类型,只需要知道是否发送成功就行了。

 

 

try {
	// 主题
	message.setSubject(theme.getText().toString());

	// 以text方式发送 内容
	// message.setText();

	// 发件人地址
	message.setFrom(new InternetAddress(adresseeString));

	// 现将数据转换为数组后添加收件人地址
	InternetAddress[] addressesArray = new InternetAddress[toList.size()];
	toList.toArray(addressesArray);
	message.addRecipients(Message.RecipientType.TO,addressesArray);

	// 现将数据转换为数组后添加抄送人地址
	if (ccList.size() > 0) {
	InternetAddress[] ccsArray = new InternetAddress[ccList.size()];
	ccList.toArray(ccsArray);
	message.addRecipients(Message.RecipientType.CC,ccsArray);
	}

	// 发送带有附件的邮件
	message = MailUtils.sendMessageBodyPart(message,content.getText().toString(), new Date(),pathList, pathNameList);

	// 设置邮件支持多种格式
	MailUtils.sendAndCollect();
        message.saveChanges();
	// 发送邮件
	Transport.send(message);

	} catch (AddressException e) {
		e.printStackTrace();
	} catch (MessagingException e) {
		e.printStackTrace();
	} catch (Throwable e) {
	<span style="white-space:pre">	</span>e.printStackTrace();
	}


在复制代码的时候我看着自己的代码都凌乱了,真心看不懂。

 

首先需要知道message接收各种人的时候需要的是数组,但是我一开始用集合是因为添加和删除比较方便,并在用户发送邮件的时候转换一下就可以了。(from-发件人,to-收件人,cc-抄送人,bcc-密送人)

 

 

以下是发送带附件邮件的方法代码,其中我们需要知道用户书写的文本数据,附件路径集合,附件名称集合,这些需要自己完成打开文件夹并点击找到该文件的路径并返回给编写邮件的activity添加到集合中

 

// 发送带有附件的邮件
public static Message sendMessageBodyPart(Message message, String text,
		Date time, List<String> pathList, List<String> pathNameList)
		throws MessagingException {

	// 时间
	message.setSentDate(new Date());
        // multipart格式邮件
	Multipart multipart = new MimeMultipart();

	BodyPart bodyPart1 = new MimeBodyPart();
	BodyPart bodyPart2 = new MimeBodyPart();

	// 以multipart方式发送邮件内容
	bodyPart1.setText(text);

	// 发送邮件附件
	// 放置文件File
	for (int i = 0; i < pathList.size(); i++) {
		// 添加附件路径
		DataSource dataSource = new FileDataSource(pathList.get(i));
		bodyPart2.setDataHandler(new DataHandler(dataSource));
		// 添加附件名称
		bodyPart2.setFileName(pathNameList.get(i));
	}

	// 添加到邮件容器中
	multipart.addBodyPart(bodyPart1);
	multipart.addBodyPart(bodyPart2);

	// 将该类型邮件容器放入message中
	message.setContent(multipart);

	return message;
	}

 

 

 

 

 

 

 

在添加完附件之后,你会发现一个设置邮件类型的方法:

 

// 设置邮件支持多种格式的发送与接收
	public static void sendAndCollect() {
		MailcapCommandMap mc = (MailcapCommandMap) CommandMap
				.getDefaultCommandMap();
		mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
		mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
		mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
		mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
		mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
		CommandMap.setDefaultCommandMap(mc);
	}

 

这就是我们需要的所有邮件主体类型。

 

 

完成以上代码片段就可以完成邮件的发送了。当然,SMTPS和以上差不了多少。在加密SSL or TLS都可以,一下是三者的对比:

 

普通邮件:
Properties props = new Properties();// key=value
       props.setProperty("mail.transport.protocol", "smtp");
       props.setProperty("mail.host",smtp);
       props.setProperty("mail.smtp.auth", "true");

 

SSL加密发送:
            Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
            final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
              Properties   props = System.getProperties();
            // 端口
            int port = 465;
            props.setProperty("mail.smtp.host", smtp);
            props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
            props.setProperty("mail.smtp.socketFactory.fallback", "false");
            props.setProperty("mail.smtp.port", String.valueOf(port));
            props.setProperty("mail.transport.protocol", "smtp");
            props.setProperty("mail.smtp.socketFactory.port",
                    String.valueOf(port));
            props.put("mail.smtp.auth", "true");

           TLS发送:
            Properties   props = System.getProperties();
            // 端口
            int port = 587;
            props.put("mail.smtp.auth", "true");
            // TODO TEST
            props.put("mail.smtp.host", smtp);
            props.put("mail.smtp.port", ""+port);
            props.put("mail.smtp.starttls.enable", "true");

 

如果你完成了以上的所有代码就可以发送自己写好的数据并发送到制定邮箱中,可能他看起来和平常工作中的不太一样(没有邮件签名,没有彩色分割线等待)。因为这是后面需要了解的HTML类型的邮件。

 

 

2.发送HTML邮件

在发送HTML邮件时要知道MIME邮箱协议:

像图中一样,邮件会通过Multipart类型来对要封装的邮件进行层层包裹,HTML,TEXT,IMAGE,附件等等。都会嵌入到其中。

multipart/mixed

混合组合类型:内容多种多样,类型可以随意组合

 

multipart/related

依赖组合类型:比如说我们需要在纯文本数据中插入图片时(不是附件),需要通过<img>标签来进行图片内嵌。此时嵌入到HTML后数据为超文本数据。

 

multipart/alternative

选择组合类型:内部存有纯文本+超文本格式的邮件,他们会成为该类型。使其提高对不同客户端的兼容。

 

可以看出最复杂的邮箱就是三者相加了。于是在我们解析邮件体时时最为麻烦的,需要分不同类型来不同解析,而又因为多层嵌套的原因我们需要方法迭代。

 

而发送方则不需要关心太多,只需要知道在合适的收好设置好你的HTML就行了。我在后面也是对HTML进行数据处理,而一般情况手机很少发送图片,当然也可以自己设置。

 

发送HTML邮件:

 

// 发送HTML邮件
	public static Message sendHTMLMessage(Message message, String text,
			List<String> pathList, List<String> pathNameList, boolean flag,
			String type) throws MessagingException, IOException {

		Multipart multipart = new MimeMultipart();

		BodyPart bodyPart1 = new MimeBodyPart();

		String content = Helps.head + text + Helps.tail;

		bodyPart1.setContent(<span style="font-family: Arial, Helvetica, sans-serif;">content </span><span style="font-family: Arial, Helvetica, sans-serif;">, "text/plain;charset=gb2312");</span>

		multipart.addBodyPart(bodyPart1);

		// 发送邮件附件
		if (flag) {
			// 放置文件File
			BodyPart bodyPart = new MimeBodyPart();
			for (int i = 0; i < pathList.size(); i++) {
				// 添加附件路径
				DataSource dataSource = new FileDataSource(pathList.get(i));
				bodyPart.setDataHandler(new DataHandler(dataSource));
				// 添加附件名称
				bodyPart.setFileName(pathNameList.get(i));
			}

			multipart.addBodyPart(bodyPart);
		}

		
		// 将该类型邮件容器放入message中
		message.setContent(multipart);

		return message;
	}

 

 

 

此时需要注意的是HTML文本格式,GB2312类型,否则中文会变成????到接收方。
Helps.head和Helps.tail是超文本数据的前部分和后部分。可以参考HTML格式来编写。

而需要在文本中内嵌图片则需要设置Content-ID和img标签。

 

String htmlText = "<H1>Hello</H1>" +

  "<img src=/"cid:memememe/">";

messageBodyPart.setContent(htmlText, "text/html");

  
// 创建一个依赖组合类型

MimeMultipart multipart = new MimeMultipart("related");
multipart.addBodyPart(messageBodyPart);

  
// 创建第二层MIME

messageBodyPart = new MimeBodyPart();

  
// 添加图片文件地址

DataSource fds = new FileDataSource(file);

messageBodyPart.setDataHandler(new DataHandler(fds));
// 设置好Content-ID名字,一定要与在img标签中设置的cid:相同
messageBodyPart.setHeader("Content-ID","memememe");

  
// 添加到容器中
multipart.addBodyPart(messageBodyPart);

  
// 放置到邮件中
message.setContent(multipart);


如上看到的,如果打开MIME邮件体中可以看到,在HTML文件中的img标签cid引用的是一个类似地址的引用。

 

此时就可以根据上面所示来添加不同的数据到邮件中并发送。

 

 

javamail收取邮件(包括附件) javamail 实例 获取pop3或者imap方式获取邮件信息,配置运行MailHelper即可. 立即下载

相关推荐

UFS电源管理实战:如何优化手机存储的功耗与性能(附实测数据)

本文深入探讨了UFS电源管理的实战优化策略,旨在平衡手机存储的功耗与性能。通过解析UFS核心电压域与工作状态,重点介绍了通过动态调整bActiveICCLevel(活动电流等级)来实现精细控制,并结合实测数据与场景驱动的智能策略,为Android系统与硬件工程师提供了降低功耗、提升流畅度的有效方法。

weixin_29214559的博客 504

android studio邮件,如何在Android Studio中获取电子邮件数据?

为什么每当我试图运行它时,崩溃我的android应用程序/将电子邮件数据导入android应用程序的最佳方式是什么?如何在Android Studio中获取电子邮件数据?该应用程序本身只包含一个按钮点击 - 我已经得到了下面的代码在eclipse中工作,我试图运行它在手机上,而不是一个模拟器,所以我不再收到网络错误。package com.example.marc.emailtest;import...

weixin_39997310的博客 980

基于WEKWS模型的语音唤醒关键词识别

本文所使用的模型网络结构继承自论文《Compact Feedforward Sequential Memory Networks for Small-footprint Keyword Spotting》,文中研究了将低秩矩阵分解与传统FSMN相结合的紧凑型前馈顺序记忆网络(cFSMN)用于远场关键字检测任务。

YuZhou的博客 6601

android使用javamail简单收发邮件功能实现

所需jar包 : mail.jar   activation.jar   additionnal.jar发送简单的文本邮件参考文章:https://blog.youkuaiyun.com/jianggujin/article/details/51253129 public void sendTextEmail()  { String port = "25";  final String userNam...

qq_37654820的博客 4442

HFSS螺旋线圈的设计与仿真

undefined.全局变量在这里进行设置:Project/Project Properties, browse and setup the global variables.undefined.方程中的局部变量设置:HFSS/Design Properties, browse and setup the local variables。按照下图填写曲线的方程内容:fill the parameters according to the setup in the following picture。

johnboat的专栏 3847

ThingsBoard教程(十九):规则节点概览介绍

在ThingsBoard的CE V2.5.6版本中,一共有这几种类型在每一种类都有包含了多个节点,每一种类型的节点都有不同的颜色表示本篇文章做一个简单的概括,后续的文章会详细讲解每一个种类的节点如何使用,每一个节点的使用。一共有10个,使用黄色表示 过滤器节点用于消息过滤和路由。一共有9个,使用绿色 属性节点用于更新传入消息的元数据。一共三个,使用蓝色 转换节点用于更改传入消息字段,如发起者、消息类型、有效负载和元数据。一共21个,使用红色标识 动作节点根据传入的消息执行各种动作。一共9个,使用黄色表示,

知无涯 1万+

关于android邮件的收发(第二弹)

前面说完发邮件,现在开始收邮件了。 对不同的协议来进行不同的处理,POP3协议邮箱在服务器上只定义一个邮箱,所以需要自己完成删除,移动,标记等功能, 而Imap则相反,大大降低了客户端代码量。 1.Imap 接收时只需要知道服务器,账户,密码就可以了,当然也可以设置端口号。 public static Message[] getAllIMAPMail(String mailBoxType

羊羊的学习旅程 1735

ADRC自抗扰PD+ESO控制(博途SCL源代码)

文章浏览阅读119次。线性自抗扰控制(LADRC)系统算法框图-优快云博客文章浏览阅读335次。NLADRC自抗扰控制从Simulink仿真到PLC控制实现_自抗扰控制器 simulink仿真-优快云博客本文介绍了如何将ADRC自抗扰控制算法从Simulink仿真应用到PLC控制中,包括Simulink框图、TD微分器模型、MATLAB函数的使用、SCL控制代码,以及非线性状态误差反馈控制率的实现。ADRC自抗扰PD+ESO控制(CODESYS测试+完整ST代码)-优快云博客。

RXXW_Dor的博客 1318

android pop3与imap方式接收邮件(javamail)

需要下载3个jar包:mail.jar/    activation.jar/    additionnal.jar 1.pop3 /** * 以pop3方式读取邮件,此方法不能读取邮件是否为已读,已经通过测试 * */ private void getEmail() { List> list = new ArrayList>(); try { Proper

Elena_wang的专栏 7420

微信小程序 - 最新实现人脸识别认证功能,使用官方微信小程序人脸识别身份验证接口及常见的人脸核验、用户实名认证、身份证件与人脸是否匹配、是否活体、领取业务人脸认证等各种示例(验证活体人脸是否匹配源码)

微信小程序中实现人脸识别认证,微信小程序人脸识别认证-微信开放接口,如何为微信小程序添加人脸识别和身份验证功能,如何为微信小程序集成人脸识别与身份验证,微信人脸识别实名认证集成指南,识别失败,人脸识别接口怎么调用,前后端完整示例代码demo,微信小程序基于小程序实现人脸识别对比,人脸识别报错,微信人脸核身接口能力,微信小程序实名认证 人脸核验 人脸识别,微信小程序实名认证与人脸核身接口全解析,微信小程序-人脸识别+输出人脸匹配信息,微信小程序实名认证人脸核验人脸识别,微信小程序实名认证:wx.startFa

🏆 前端领域优质创作者 3277

科研绘图系列:R语言折线图(linechart plots)

科研绘图系列:R语言折线图(linechart plots)

专注生信领域 1272

Android邮件发送实现

这里邮件的实现方式使用的是 JavaMail for Andorid,用到的包主要有android-mail和android-activation,具体详情可以参考:https://javaee.github.io/javamail/#JavaMail_for_Android,这里使用的Android studio进行开发,首先是进行配置: repositories { jcente...

tangedegushi的博客 2万+

打破RK3588 GPIO中断响应延迟的枷锁,开启高效编程

本文针对RK3588芯片在智能安防和工业自动化应用中出现的GPIO中断响应延迟问题展开深入分析。通过硬件原理剖析,发现延迟主要源于中断控制器优先级设置、线路干扰等硬件因素,以及中断处理函数复杂、内核调度延迟等软件问题。提出硬件优化方案包括合理布局布线、电源稳定设计,软件层面则通过精准配置设备树、精简中断处理函数、利用工作队列等内核机制进行优化。测试结果显示,优化后中断响应延迟从50-80ms降至10-20ms,高负载下也能稳定在50ms以内。文章最后展望了AI技术在中断调度中的潜在应用价值。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 364

基于Android的邮件收发

基于Android的邮件收发

weixin_34195364的博客 170

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android邮件服务,关于android邮件的收发

讲到android的邮件收发,首先就要讲讲关于邮件协议的一下基础,度娘基本都有,这里是怕自己忘记,贴点备忘录。现在常用的电子邮件协议有SMTP(25)、POP3(110)、IMAP4(143)。他们都处于TCP/IP协议簇,还包括他们的加密协议,SMTPS(465)、POPS(995)、IMAPS(993),他们的默认端口号都在后面的小括号里面了。其中的细节就不讲了,SMTP协议负责发送邮件,而P...

weixin_26782843的博客 1048

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

android平台收发邮件

转自:http://blog.sina.com.cn/s/blog_56e5b1410101lael.html 一、开发前准备 1、下载jar包,下载地址 http://code.google.com/p/javamail-android/downloads/list additionnal.jar、mail.jar 和 activation.jar 2、在eclipse中新建一个and

Elena_wang的专栏 3193

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

android 获取邮件内容,android 收发邮件(发送邮件、读取收件列表等)亲测通过

【实例简介】【实例截图】【核心代码】package mi.email.activity;import mi.learn.com.R;import android.app.Activity;import android.app.Dialog;import android.app.ProgressDialog;import android.content.Intent;import android.o...

weixin_32920055的博客 1055

Android系统手机邮件收发设置教程

智能手机、移动网络应用的大众化普及,让最初只能靠电脑办公的业务,逐步走向了手机终端。企业邮箱与手机终端的接合就是最早的商务应用之一。而 Android手机则以53%的市场占有率,成为全球主流。这里,笔者就以Android手机给大家介绍一下,企业自建邮件服务器后,应如何进行手机邮件 收发设置。 范例邮箱信息: 用户邮箱账号:hqq@comingchina.com 邮箱服务器地:...

weixin_30572613的博客 301

android平台收发邮件教程

http://blog.sina.com.cn/s/blog_56e5b1410101lael.html 一、开发前准备 1、下载jar包,下载地址 http://code.google.com/p/javamail-android/downloads/list additionnal.jar、mail.jar 和 activation.jar 2、在ec

zzzhhhjjj3的专栏 749

java resolvemail_Android 基于Android的手机邮件收发(JavaMail)之三(邮件接收)

初次做这个程序的时候,是仿照着网上别人的程序做的。因为本人比较菜,是一个新手,以前的基础知识没有学好,所以尽管有了别人的代码但是还是不知道怎么在界面上显示出它的效果来,废话不多少,现在就贴出我的参考程序的来源。http://www.cnblogs.com/love2009/archive/2009/02/24/1397201.html大家可以在看以下内容前,通读一下。想要了解javamail的机...

weixin_28707739的博客 2566

Android选择默认邮件程序,使用安卓手机默认邮件程序设置好了EXCHANGE协议的OUTLOOK.COM账户,但无法收发邮件。...

问题未解决,具体情况如下:发现了安卓手机设备被状态是已隔离。应对如下:1,已经在设备列表里都清除了。2,删除手机OUTLOOKAPP中账户3,删除手机邮件中EXCHANGE账户3,重启手机4,用OUTLOOKapp重新登录用户账户5,OUTLOOKAPP可以正常收发邮件6,此时移动设备列表中并未出现任何一台安卓设备7, 使用电脑打开网址的链接,网页仍是RUNTIME ERROR8,我再次使...

weixin_42364392的博客 1158

android 使用javamail收发邮件

1 发送邮件 今天学习了一下JavaMail,javamail发送邮件确实是一个比较麻烦的问题不用第三方邮件程序。为了以后使用方便,自己写了段代码. Javamail-Android配置步骤: 下载Android版本JavaMail包,additional.jar、mail.jar和activation.jar,下载地址JavaMail-Android 在项

svenke2011的专栏 9961

android 邮件收发功能,Android中使用Service实现后台发送邮件功能实例

本文实例讲述了Android中使用Service实现后台发送邮件功能。分享给大家供大家参考,具体如下:程序如下:import android.app.Activity;import android.content.Intent;import android.content.res.Resources.NotFoundException;import android.os.Bundle;import...

weixin_31974443的博客 479
上一篇: 关于语言的前期绑定与后期绑定
下一篇: 关于android邮件的收发(第二弹)
羊羊爱代码
博客等级 码龄11年 8粉丝 28原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值