首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

Java---通过smtp模拟发信

public class MailUtil { public static MimeMessage createMimeMessage(Session session, String sendMail, String receivename, String receiveMail, String subject, String content) throws Exception { // 1. 创建一封邮件 MimeMessage message = new MimeMessage(session); // 2. From: 发件人 message.setFrom(new InternetAddress(sendMail, "发件人名称", "UTF-8")); // 3. To: 收件人(可以增加多个收件人、抄送、密送) message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, receivename, "UTF-8")); // 4. Subject: 邮件主题 message.setSubject(subject, "UTF-8"); // 5. Content: 邮件正文(可以使用html标签) MimeBodyPart text = new MimeBodyPart(); text.setContent(content, "text/html;charset=UTF-8"); MimeMultipart mp = new MimeMultipart(); mp.addBodyPart(text); mp.setSubType("mixed"); message.setContent(mp); message.saveChanges(); // 6. 设置发件时间 message.setSentDate(new Date()); // 7. 保存设置 message.saveChanges(); return message; } public static void sendmail(String content,String recivemail) throws Exception{ Properties props = new Properties(); props.put("mail.smtp.host", "smtp服务器地址"); props.put("mail.smtp.starttls.enable","true");//使用 STARTTLS安全连接 props.put("mail.smtp.port", "smtp服务器端口"); //google使用465或587端口 props.put("mail.smtp.auth", "true"); // 使用验证 props.put("mail.debug", "true"); Session mailSession = Session.getInstance(props,new MyAuthenticator("发信的邮箱地址","发信的邮箱密码")); Transport transport = mailSession.getTransport("smtp"); transport.connect("smtp服务器地址","发信的邮箱地址","发信的邮箱密码"); MimeMessage m=MailUtil.createMimeMessage(mailSession, "发件邮箱","收件人姓名", recivemail,"主题",content); transport.sendMessage(m, m.getAllRecipients()); transport.close(); } } class MyAuthenticator extends Authenticator{ String userName=""; String password=""; public MyAuthenticator(){ } public MyAuthenticator(String userName,String password){ this.userName=userName; this.password=password; } protected PasswordAuthentication getPasswordAuthentication(){ return new PasswordAuthentication(

02

一个人的服务器端

能够做这个MMO的触发点是通过某些途径得到了某个大公司使用的一款3D引擎,其他的都是白手起家。当时大家还不知道有“分布式服务器端”一说,服务器端框架参考了《剑3》:剑3内测的时候经常服务器crash,但是每次只crash一个地图,所以可以推知他们是一个地图一个server;加上自己对服务器端的认识,需要Gate当防火墙,需要GameServer来总管MapServer,需要DB来存储,那么最初的服务器端框架就定下来了:Gate、GameServer、MapServer、DBServer。想让服务器之间的连接方式最简化,所以确定GameServer是中心,其他Server都连接并且只连接GameServer。MapServer和GameServer上面准备加脚本,脚本直接选择了python,因为python语法清晰一点。开发平台选择windows,因为当时公司内没有一个人了解linux。

03
领券