精华内容
下载资源
问答
  • 匿名邮件发送工具可以帮你发送匿名邮件,如果你想给某人发一封邮件却不想让其知道你的邮箱地址,用这个软件就能实现,利用它我们就可以发送带有附件的匿名邮件了,一定会成为
  • 邮件发送工具

    2019-11-27 15:30:05
    代码如下: import ... import lombok.extern.slf4j.Slf4j; import javax.mail.*;...import javax.mail.internet.InternetAddress;...import javax.mail.internet.MimeBodyPart;...import javax.m...

    代码如下:

    
    
    import com.es.util.utilpojo.Order;
    import lombok.extern.slf4j.Slf4j;
    
    import javax.mail.*;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    import java.util.Properties;
    
    
    @Slf4j
    public class EmailUtil {
        public String execute(Order order) {
            try {
                String to[]=order.getAddressee().split(";");
                String host = "smtp.exmail.qq.com";//邮件主机地址
                Properties props = new Properties();
                props.put("mail.transport.protocol", "smtp");// 连接协议
                props.put("mail.smtp.host", host);// 主机名
                props.put("mail.smtp.port", 465);// 端口号
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.ssl.enable", "true");// 设置是否使用ssl安全连接 ---一般都使用
                props.put("mail.debug", "true");// 设置是否显示debug信息 true 会在控制台显示相关信息
                // 得到回话对象
                Session mailSession = Session.getInstance(props);
                // 获取邮件对象
                MimeMessage mailMessage = new MimeMessage(mailSession);
                // 设置发件人邮箱地址
                mailMessage.setFrom(new InternetAddress("123456@qq.com"));
    
                //设置收信人
                Address[] toAddr = new InternetAddress[to.length];
                for (int i = 0; i < to.length; i++) {
                    toAddr[i] = new InternetAddress(to[i]);
                }
                mailMessage.setRecipients(Message.RecipientType.TO, toAddr);
    
                //设置抄送人
                if(order.getCcemail()!=null&&order.getCcemail().length()>0){
                    String cc[]=order.getCcemail().split(";");
                    Address[] ccAddr = new InternetAddress[cc.length];
                    for (int i = 0; i < cc.length; i++) {
                        ccAddr[i] = new InternetAddress(cc[i]);
                    }
                    mailMessage.setRecipients(Message.RecipientType.CC, ccAddr);
                }
                mailMessage.setSubject(order.getSubject());
                mailMessage.setSentDate(new java.util.Date());
                //MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象
                Multipart mainPart = new MimeMultipart();
                //创建一个包含HTML内容的MimeBodyPart
                BodyPart html = new MimeBodyPart();
                //设置HTML内容
    
                html.setContent(order.getBody(), "text/html; charset=utf-8");
                mainPart.addBodyPart(html);
                // 将MiniMultipart对象设置为邮件内容
                mailMessage.setContent(mainPart);
                mailMessage.saveChanges();
    
                //发送邮件
                Transport transport = mailSession.getTransport("smtp");
                log.info("======开始连接邮箱服务器");
                transport.connect(host, "123456@qq.com", "Timer123");
                log.info("======连接邮箱服务器成功");
                transport.sendMessage(mailMessage, mailMessage.getAllRecipients());
                transport.close();
                log.info("======关闭连接邮箱服务器");
            }catch(Exception e) {
                log.error("Send to ["+order.getAddressee()+" "+order.getCcemail()+"] error: "+e);
            }
            return null;
        }
    
    
        public static void main(String[] args) {
            EmailUtil handler = new EmailUtil();
            Order order = new Order();
            order.setSender("123456@qq.com");//发送人邮箱
            order.setAddressee("456789484@qq.com");//收信人邮箱,多个收信人之间;号间隔
            order.setCcemail("13925856458@139.com");//抄送人邮箱,多个抄送人之间;号间隔
            order.setSubject("测试标题");//标题
            order.setBody("测试正文");//正文
            handler.execute(order);
        }
    
    }
    

    Order类

    
    
    import lombok.Data;
    
    @Data
    public class Order {
    
        private String sender;//发信人
        private String addressee;//收信人邮箱,多个收信人之间;号间隔
        private String ccemail;//抄送人邮箱,多个抄送人之间;号间隔
        private String subject;//标题
        private String body;//正文
    
    }
    

     

    输出结果

    展开全文
  • 易语言邮件发送工具源码,邮件发送工具
  • java邮件发送工具

    2020-04-01 14:54:16
    java邮件发送工具类包含附件正常发送 亲测有效,附件正常显示解决内容和附件不能同事显示问题!测试成功实现内容和附件同时发送成功
  • 易语言源码易语言邮件发送工具源码.rar 易语言源码易语言邮件发送工具源码.rar 易语言源码易语言邮件发送工具源码.rar 易语言源码易语言邮件发送工具源码.rar 易语言源码易语言邮件发送工具源码.rar 易语言源码...
  • 阿里巴巴邮件发送工具类,包括所需要的架包,复制粘贴到项目中,配置用户名和密码可直接发送邮件,有问题请留言
  • JAVA邮件发送工具类(支持同步和异步发送邮件以及附件信息),支持多个抄送邮件发送。
  • QT编写的邮件发送工具

    热门讨论 2014-03-12 19:33:29
    项目名称:邮件发送工具 开发环境:XP+QT4.7+QT CREATOR2.8+MINGW 已编译通过测试平台:XP、Win7、ubuntu、tiny210、TE6410 技术实现:通过socket通信实现smtp协议,根据应答解析协议并作出处理发送邮件 基本功能: ...
  • 邮件发送工具

    2021-01-21 11:05:35
    邮件发送工具类 package com.util; import java.io.File; import java.util.Date; import java.util.List; import java.util.Properties; import javax.activation.DataHandler; import javax.activation....

    邮件发送工具类

    package com.util;
    
    import java.io.File;
    import java.util.Date;
    import java.util.List;
    import java.util.Properties;
    
    import javax.activation.DataHandler;
    import javax.activation.DataSource;
    import javax.activation.FileDataSource;
    import javax.mail.Authenticator;
    import javax.mail.BodyPart;
    import javax.mail.Message;
    import javax.mail.Multipart;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    import javax.mail.internet.MimeUtility;
    
    //import com.chinainsurance.application.platform.dto.domain.GgCodeTransferDto;
    
    public class SendMail {
    	private String mail_host = ""; // 发信服务器地址
    	private String mail_port = "25"; // 发信服务器端口
    	private String userName = ""; // 发件人账号
    	private String password = ""; // 发件人密码
    
    	/**
    	 * 发送文本邮件
    	 * 
    	 * @param to
    	 *            收件人
    	 * @param subject
    	 *            标题
    	 * @param sentDate
    	 *            发信日期
    	 * @param text
    	 *            文本内容
    	 * @throws Exception
    	 */
    	public void sendTextMail(String to, String subject, Date sentDate,
    			String text) throws Exception {
    		Properties pro = System.getProperties();
    		pro.put("mail.smtp.host", mail_host);
    		pro.put("mail.smtp.port", mail_port);
    		pro.put("mail.smtp.auth", "true");
    
    		// 根据邮件会话属性和密码验证器构造一个发送邮件的session
    		Session sendMailSession = Session.getDefaultInstance(pro,
    				new Authenticator() {
    					@Override
    					protected PasswordAuthentication getPasswordAuthentication() {
    						return new PasswordAuthentication(userName, password);
    					}
    				});
    		// 根据session创建一个邮件消息
    		Message mailMessage = new MimeMessage(sendMailSession);
    		// 设置邮件消息的发送者
    		mailMessage.setFrom(new InternetAddress(userName));
    		// 创建邮件的接收者地址,并设置到邮件消息中
    		mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(
    				to));
    		// 设置邮件消息的主题
    		mailMessage.setSubject(subject);
    		// 设置邮件消息发送的时间
    		mailMessage.setSentDate(sentDate);
    		// 设置邮件消息的主要内容
    		mailMessage.setText(text);
    		// 发送邮件
    		Transport.send(mailMessage);
    	}
    
    	/**
    	 * 发送Html邮件
    	 * 
    	 * @throws Exception
    	 */
    	public void sendHtmlMail(List<GgCodeTransferDto> toList,
    			List<GgCodeTransferDto> ccList, String subject, Date sentDate,
    			String text) throws Exception {
    		Properties pro = System.getProperties();
    		pro.put("mail.smtp.host", mail_host);
    		pro.put("mail.smtp.port", mail_port);
    		pro.put("mail.smtp.auth", "true");
    
    		// 根据邮件会话属性和密码验证器构造一个发送邮件的session
    		Session sendMailSession = Session.getDefaultInstance(pro,
    				new Authenticator() {
    					@Override
    					protected PasswordAuthentication getPasswordAuthentication() {
    						return new PasswordAuthentication(userName, password);
    					}
    				});
    		// 根据session创建一个邮件消息
    		Message mailMessage = new MimeMessage(sendMailSession);
    		// 设置邮件消息的发送者
    		mailMessage.setFrom(new InternetAddress(userName));
    
    		InternetAddress[] address = new InternetAddress[toList.size()];
    		InternetAddress[] addressCc = new InternetAddress[ccList.size()];
    		// 创建邮件的接收者地址,并设置到邮件消息中
    		if (toList != null && toList.size() > 0) {
    			for (int i = 0; i < toList.size(); i++) {
    				address[i] = new InternetAddress(toList.get(i).getOuterCode());
    			}
    		}
    		
    		// 抄送
    		if (ccList != null && ccList.size() > 0) {
    			for (int j = 0; j < ccList.size(); j++) {
    				addressCc[j] = new InternetAddress(ccList.get(j).getOuterCode());
    			}
    		}
    
    		if (address != null && address.length > 0) {
    			mailMessage.setRecipients(Message.RecipientType.TO, address);
    			if (addressCc != null && addressCc.length > 0) {
    				mailMessage.setRecipients(Message.RecipientType.CC, addressCc);
    			}
    		} else {
    			if (addressCc != null && addressCc.length > 0) {
    				mailMessage.setRecipients(Message.RecipientType.TO, addressCc);	
    			}
    		}
    
    		// 设置邮件消息的主题
    		mailMessage.setSubject(subject);
    		// 设置邮件消息发送的时间
    		mailMessage.setSentDate(sentDate);
    
    		// MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象
    		Multipart mainPart = new MimeMultipart();
    		// 创建一个包含HTML内容的MimeBodyPart
    		BodyPart html = new MimeBodyPart();
    		// 设置HTML内容
    		html.setContent(text, "text/html; charset=utf-8");
    		mainPart.addBodyPart(html);
    		// 将MiniMultipart对象设置为邮件内容
    		mailMessage.setContent(mainPart);
    		// 发送邮件
    		Transport.send(mailMessage);
    	}
    
    	/**
    	 * 发送Html邮件
    	 * 
    	 * @throws Exception
    	 */
    	public void sendHtmlMail2(String to, String cto, String subject,
    			Date sentDate, String text) throws Exception {
    		Properties pro = System.getProperties();
    		pro.put("mail.smtp.host", mail_host);
    		pro.put("mail.smtp.port", mail_port);
    		pro.put("mail.smtp.auth", "true");
    
    		// 根据邮件会话属性和密码验证器构造一个发送邮件的session
    		Session sendMailSession = Session.getDefaultInstance(pro,
    				new Authenticator() {
    					@Override
    					protected PasswordAuthentication getPasswordAuthentication() {
    						return new PasswordAuthentication(userName, password);
    					}
    				});
    		// 根据session创建一个邮件消息
    		Message mailMessage = new MimeMessage(sendMailSession);
    		// 设置邮件消息的发送者
    		mailMessage.setFrom(new InternetAddress(userName));
    		// 创建邮件的接收者地址,并设置到邮件消息中
    		InternetAddress[] address = new InternetAddress[1];
    		address[0] = new InternetAddress(to);
    		mailMessage.setRecipients(Message.RecipientType.TO, address);
    
    		// 抄送
    		if (cto != null) {
    			InternetAddress[] addressCc = new InternetAddress[1];
    			addressCc[0] = new InternetAddress(cto);
    			mailMessage.setRecipients(Message.RecipientType.CC, addressCc);
    		}
    
    		// 设置邮件消息的主题
    		mailMessage.setSubject(subject);
    		// 设置邮件消息发送的时间
    		mailMessage.setSentDate(sentDate);
    
    		// MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象
    		Multipart mainPart = new MimeMultipart();
    		// 创建一个包含HTML内容的MimeBodyPart
    		BodyPart html = new MimeBodyPart();
    		// 设置HTML内容
    		html.setContent(text, "text/html; charset=utf-8");
    		mainPart.addBodyPart(html);
    		// 将MiniMultipart对象设置为邮件内容
    		mailMessage.setContent(mainPart);
    		// 发送邮件
    		Transport.send(mailMessage);
    	}
    
    	/**
    	 * 发送内嵌图片邮件
    	 * 
    	 * @throws Exception
    	 */
    	public void sendImageMail() throws Exception {
    		Properties pro = System.getProperties();
    		pro.put("mail.smtp.host", mail_host);
    		pro.put("mail.smtp.port", mail_port);
    		pro.put("mail.smtp.auth", "true");
    
    		// 根据邮件会话属性和密码验证器构造一个发送邮件的session
    		Session sendMailSession = Session.getDefaultInstance(pro,
    				new Authenticator() {
    					@Override
    					protected PasswordAuthentication getPasswordAuthentication() {
    						return new PasswordAuthentication(userName, password);
    					}
    				});
    		// 根据session创建一个邮件消息
    		Message mailMessage = new MimeMessage(sendMailSession);
    		// 设置邮件消息的发送者
    		mailMessage.setFrom(new InternetAddress(userName));
    		// 创建邮件的接收者地址,并设置到邮件消息中
    		// mailMessage.setRecipient(Message.RecipientType.TO,
    		// new InternetAddress(to));
    		// 设置邮件消息的主题
    		mailMessage.setSubject("Test Email");
    		// 设置邮件消息发送的时间
    		mailMessage.setSentDate(new Date());
    
    		MimeMultipart multipart = new MimeMultipart("related");
    
    		BodyPart messageBodyPart = new MimeBodyPart();
    		String htmlText = "<html><body><img src='cid:image'/><div>this is a HTML email.</div></body></html>";
    		messageBodyPart.setContent(htmlText, "text/html; charset=utf-8");
    		multipart.addBodyPart(messageBodyPart);
    
    		MimeBodyPart imageBodyPart = new MimeBodyPart();
    		DataSource fds = new FileDataSource("1_jianggujin.jpg");
    		imageBodyPart.setDataHandler(new DataHandler(fds));
    		// imageBodyPart.setContentID("image");
    		multipart.addBodyPart(imageBodyPart);
    
    		mailMessage.setContent(multipart);
    		// 发送邮件
    		Transport.send(mailMessage);
    	}
    
    	/**
    	 * 发送附件邮件
    	 * 
    	 * @throws Exception
    	 */
    	public void sendAttachmentMail() throws Exception {
    		Properties pro = System.getProperties();
    		pro.put("mail.smtp.host", mail_host);
    		pro.put("mail.smtp.port", mail_port);
    		pro.put("mail.smtp.auth", "true");
    
    		// 根据邮件会话属性和密码验证器构造一个发送邮件的session
    		Session sendMailSession = Session.getDefaultInstance(pro,
    				new Authenticator() {
    					@Override
    					protected PasswordAuthentication getPasswordAuthentication() {
    						return new PasswordAuthentication(userName, password);
    					}
    				});
    		// 根据session创建一个邮件消息
    		Message mailMessage = new MimeMessage(sendMailSession);
    		// 设置邮件消息的发送者
    		mailMessage.setFrom(new InternetAddress(userName));
    		// 创建邮件的接收者地址,并设置到邮件消息中
    		// mailMessage.setRecipient(Message.RecipientType.TO,
    		// new InternetAddress(to));
    		// 设置邮件消息的主题
    		mailMessage.setSubject("Test Email");
    		// 设置邮件消息发送的时间
    		mailMessage.setSentDate(new Date());
    
    		MimeMultipart multipart = new MimeMultipart("mixed");
    
    		BodyPart messageBodyPart = new MimeBodyPart();
    		String htmlText = "<html><body><div>this is a Attachment email.this email has a attachment!</div></body></html>";
    		messageBodyPart.setContent(htmlText, "text/html; charset=utf-8");
    		multipart.addBodyPart(messageBodyPart);
    
    		MimeBodyPart imageBodyPart = new MimeBodyPart();
    		File imageFile = new File("1_jianggujin.jpg");
    		DataSource fds = new FileDataSource(imageFile);
    		imageBodyPart.setDataHandler(new DataHandler(fds));
    		imageBodyPart.setFileName(MimeUtility.encodeWord(imageFile.getName()));
    		multipart.addBodyPart(imageBodyPart);
    
    		mailMessage.setContent(multipart);
    		// 发送邮件
    		Transport.send(mailMessage);
    	}
    
    	/**
    	 * 发送内嵌图片和附件邮件
    	 * 
    	 * @throws Exception
    	 */
    	public void sendImageAndAttachmentMail() throws Exception {
    		Properties pro = System.getProperties();
    		pro.put("mail.smtp.host", mail_host);
    		pro.put("mail.smtp.port", mail_port);
    		pro.put("mail.smtp.auth", "true");
    
    		// 根据邮件会话属性和密码验证器构造一个发送邮件的session
    		Session sendMailSession = Session.getDefaultInstance(pro,
    				new Authenticator() {
    					@Override
    					protected PasswordAuthentication getPasswordAuthentication() {
    						return new PasswordAuthentication(userName, password);
    					}
    				});
    		// 根据session创建一个邮件消息
    		Message mailMessage = new MimeMessage(sendMailSession);
    		// 设置邮件消息的发送者
    		mailMessage.setFrom(new InternetAddress(userName));
    		// 创建邮件的接收者地址,并设置到邮件消息中
    		// mailMessage.setRecipient(Message.RecipientType.TO,
    		// new InternetAddress(to));
    		// 设置邮件消息的主题
    		mailMessage.setSubject("Test Email");
    		// 设置邮件消息发送的时间
    		mailMessage.setSentDate(new Date());
    
    		// 正文
    		MimeBodyPart text = new MimeBodyPart();
    		text.setContent("我的头像:<img src='cid:headImg'>",
    				"text/html;charset=UTF-8");
    
    		// 正文图片
    		MimeBodyPart image = new MimeBodyPart();
    		image.setDataHandler(new DataHandler(new FileDataSource(
    				"1_jianggujin.jpg")));
    		// image.setContentID("headImg");
    
    		// 附件
    		MimeBodyPart attach = new MimeBodyPart();
    		DataHandler dh = new DataHandler(new FileDataSource("1_jianggujin.jpg"));
    		attach.setDataHandler(dh);
    		attach.setFileName(MimeUtility.encodeWord(dh.getName()));
    
    		// 描述关系:正文和图片
    		MimeMultipart mp1 = new MimeMultipart();
    		mp1.addBodyPart(text);
    		mp1.addBodyPart(image);
    		mp1.setSubType("related");
    
    		// 正文
    		MimeBodyPart content = new MimeBodyPart();
    		content.setContent(mp1);
    
    		MimeMultipart multipart = new MimeMultipart("mixed");
    		multipart.addBodyPart(content);
    		multipart.addBodyPart(attach);
    
    		mailMessage.setContent(multipart);
    		// 发送邮件
    		Transport.send(mailMessage);
    	}
    }
    
    展开全文
  • java 邮件发送工具

    千次阅读 2016-01-06 10:20:31
    java 邮件发送 工具

    最近在做一个java发送邮件的工具类,现在分享一下完整的代码
    首先需要java邮件的包javax.mail-1.5.4.jar
    之前因为链接给错了,很不好意思,现在重新发一次。
    包在这里可以下载http://download.csdn.net/detail/sun2015_07_24/9392090

    package com.neusoft.util;
    
    
    import java.io.UnsupportedEncodingException;
    import java.util.Date;
    import java.util.Properties;
    
    import javax.mail.Address;
    import javax.mail.Message;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    
    /**
     * 邮件发送工具类
     */
    public class SendMailUtil {
        /**
         * 邮件发送的方法
         * 
         * @param to 收件人
         * @param subject 主题
         * @param content 内容
         * @param smtp 协议
         * @param host 发送服务器服务器
         * @param sendName 邮件发送人
         * @param sendPort 邮件发送人端口
         * @param userName 邮件发送人名
         * @param userPwd 邮件发送人密码
         * @return 成功或失败
         */
        public static boolean send(String to, String subject, String content, String smtp, String host,
                String sendName, String sendPort, String userName, String userPwd) {
    
            // 第一步:创建Session
            Properties props = new Properties();
            // 指定邮件的传输协议,smtp(Simple Mail Transfer Protocol 简单的邮件传输协议)
            props.put("mail.transport.protocol", smtp);
            // 指定邮件发送服务器服务器 "smtp.qq.com"
            props.put("mail.host", host);
            // 指定邮件的发送人(您用来发送邮件的服务器,比如您的163\sina等邮箱)
            props.put("mail.from", sendName);
            if (true) {
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtp.socketFactory.fallback", "false");
                props.put("mail.smtp.socketFactory.port", sendPort);
            }
            Session session = Session.getDefaultInstance(props);
    
            // 开启调试模式
            session.setDebug(true);
            try {
                // 第二步:获取邮件发送对象
                Transport transport = session.getTransport();
                // 连接邮件服务器,链接您的163、sina邮箱,用户名(不带@163.com,登录邮箱的邮箱账号,不是邮箱地址)、密码
                transport.connect(userName, userPwd);
                Address toAddress = new  InternetAddress(to);
    
                // 第三步:创建邮件消息体
                MimeMessage message = new MimeMessage(session);
                //设置自定义发件人昵称
                String nick="";
                try {
                    nick=javax.mail.internet.MimeUtility.encodeText("我的昵称");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } 
                message.setFrom(new InternetAddress(nick+" <"+sendName+">"));
              //设置发信人
               // message.setFrom(new InternetAddress(sendName));
    
                // 邮件的主题
                message.setSubject(subject);
                //收件人
                message.addRecipient(Message.RecipientType.TO, toAddress); 
                /*//抄送人
                Address ccAddress = new InternetAddress("first.lady@whitehouse.gov"); 
                message.addRecipient(Message.RecipientType.CC, ccAddress);*/
                // 邮件的内容
                message.setContent(content, "text/html;charset=utf-8");
                // 邮件发送时间
                message.setSentDate(new Date());
    
                // 第四步:发送邮件
                // 第一个参数:邮件的消息体
                // 第二个参数:邮件的接收人,多个接收人用逗号隔开(test1@163.com,test2@sina.com)
                transport.sendMessage(message, InternetAddress.parse(to));
                return true;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return false;
        }
    
        public static void main(String[] args) {
            // 您要发送给谁,标题,内容
            SendMailUtil.send("*****@qq.com", "标题", "内容", "smtp", "smtp.qq.com", "发送人名", "端口号", "用户名", "密码");
        }
    }
    
    展开全文
  • javamail邮件发送工具类 封装好的 可直接使用
  • PHP邮件发送工具

    2019-02-19 20:42:19
    * 邮件发送工具类 */ class Mail { const ENCODING = 'utf-8'; /** * 发件人信息 */ private static $sendMailer = null; /** * 邮件发送接口地址 */ private static $host = "htt...

    承接上一篇文章,这里放一个自己写的类文件,仅供参考!!!

    <?php
    /**
    * 邮件发送工具类
    */
    class Mail
    {
    	const ENCODING = 'utf-8';
    	/**
    	* 发件人信息
    	*/
    	private static $sendMailer = null;
    	/**
    	* 邮件发送接口地址
    	*/
    	private static $host = "http://*****";
    	/**
    	* 邮件发送接口路径
    	*/
    	private static $query;
    	/**
    	* HTTP头
    	*/
    	private static $headers;
    
    	/**
    	* 初始化发件人信息
    	*/
    	public static function init(){
    		self::$sendMailer = array(
    			//账号
    			'username' => '',
    			//密码
    			'password' => '',
    			//发件人名
    			'from_name' => '',
    			//发件来源email地址
    			'from_mail' => '',
    			);
    	}
    	/**
    	* 设置发件人信息
    	*/
    	public function setFrom($sendMailer){
    		if (!empty($sendMailer)) {
    			self::$sendMailer = $sendMailer;
    		}
    	}
    	/**
    	* 邮件发送
    	* $email_to 	收件人地址
    	* $title  		标题
    	* $content   	正文
    	* $attachment  	附件array(array('datatype' => 'data/path','data' => ,'filename' => )) 当datatype为data时,data为附件内容;当为path时,为全路径
    	* $email_cs 	抄送array('aaa@email.com','bbb@email.com')
    	* $email_as		暗送array('aaa@email.com','bbb@email.com')
    	* $throwException 当值为true,有异常则抛出
    	*/
    	public static function sendemail($email_to,$title,$content,$attachment = null,$email_cs = null,$email_as = null,$throwException = false){
    		try{
    			if (self::$sendMailer == null) {
    				self::init();
    			}
    			if (empty($email_to)) {
    				throw new Exception("发邮件出错:接收者为空!");
    			}
    			if (is_string($email_to)) {
    				$email_to = explode(',', $email_to);
    			}
    			$title = iconv(self::ENCODING,"utf-8//IGNORE",$title);
    			$content = iconv(self::ENCODING,"utf-8//IGNORE",$content);
    			$origin = array('appFlag' => '','outTsn' => time());
    			$mail = array(
    				'subject' => $title,
    				'from' => array(
    					'name' => iconv(self::ENCODING,"utf-8//IGNORE",self::$sendMailer['from_name']),
    					'mail' => self::$sendMailer['from_mail']
    					),
    				'to' => array(),
    				'cs' => array(),
    				'as' => array(),
    				'htmlMsg' => chunk_split(base64_encode($content)),
    				'textMsg' => $content,
    				'mailType' => '',
    				'username' => self::$sendMailer['username'],
    				'password' => self::$sendMailer['password']
    				);
    			//配置收件人、抄送人、暗送人
    			foreach ($email_to as $value) {
    				if($value && strpos($value,"@") !== false){
    					$mail['to'][] = self::getMailMsg($value);
    				}
    			}
    			//如果有抄送,设置抄送人员
    			if ($email_cs) {
    				if (!is_array($email_cs)) {
    					$email_cs = explode(',',$email_cs);
    				}
    				foreach ($email_cs as $value) {
    					if($value && strpos($value,"@") !== false){
    						$mail['cs'][] = self::getMailMsg($value);
    					}
    				}
    			}
    			//如果有暗送,设置暗送人员
    			if ($email_as) {
    				if (!is_array($email_as)) {
    					$email_as = explode(',',$email_as);
    				}
    				foreach ($email_as as $value) {
    					if($value && strpos($value,"@") !== false){
    						$mail['as'][] = self::getMailMsg($value);
    					}
    				}
    			}
    			//如果有附件,则设置附件信息
    			if ($attachment && is_array($attachment)) {
    				$mail['mailType'] =self::isHTML($content) ? "html_multipart" : "multipart";
    				self::setQuery('/emailto/send/multipart');
    				self::setHeaders(array('Content-Type:multipart/form-data; charset=UTF-8'));
    				$send_message = array(
    					'origin' => json_encode($origin),
    					'mailData' => json_encode($mail)
    					);
    				$i = 1;
    				$attachment_name = '';
    				foreach ($attachment as $one) {
    					if (!empty($one['datatype']) && !empty($one['data'])) {
    						switch ($one['datatype']) {
    							case 'path':
    								$file_content = self::getFileData($one['data']);
    								break;
    							case 'data':
    								$file_content = $one['data'];
    								break;
    							default:
    								$file_content = '';
    						}
    						$attachment_name .= iconv(self::ENCODING,"utf-8//IGNORE",$one['filename']) . ";";
    						$send_message['attachmentData_' . $i] = $file_content;
    						$i++;
    					}
    				}
    				$send_message['attachmentName'] = rtrim($attachment_name,";");
    				$send = self::send($send_message);
    			}else{
    				$mail['mailType'] =self::isHTML($content) ? "html" : "simple";
    				self::setQuery('/emailto/send/simple');
    				self::setHeaders(array('Content-Type:application/json; charset=UTF-8'));
    				$send_message = array(
    					'origin' => $origin,
    					'mail' => $mail
    					);
    				$send = self::send(json_encode($send_message));
    			}
    			if (!$send['code']) {
    				throw new Exception($send['msg']);
    			}
    		} catch(Exception $e){
    
    		}
    		return true;
    	}
    	/**
    	* 发送邮件函数
    	*/
    	private static function send($mail_message){
    		$ch = curl_init();
    		$url = rtrim(self::getHost(),"/") . self::getQuery();
    		curl_setopt($ch, CURLOPT_URL, $url);
    		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    		curl_setopt($ch, CURLOPT_HTTPHEADER, self::getHeaders());
    		curl_setopt($ch, CURLOPT_POSTFIELDS, $mail_message);
    		$result = curl_exec($ch);
    		$error = curl_error($ch);
    		$result_arr = json_decode($result);
    		if (isset($result_arr->status) && $result_arr->status == 1 && $result_arr->statusMsg == 'SUCCESS') {
    			return array('code' => 1);
    		} else {
    			return array('code' => 0, 'msg' =>$error . "\n" .$result);
    		}
    	}
    	/**
    	* 处理邮件信息
    	*/
    	private static function getMailMsg($email,$name = null){
    		if (empty($name)) {
    			$arr = explode("@", $email);
    			$name = $arr['0'];
    		}
    		return array('name' => $name, 'mail' => $email);
    	}
    	/**
    	* 检查邮件内容是否是html
    	*/
    	private static function isHTML($content){
    		return $content != strip_tags($content);
    	}
    	/**
    	* 取文件内容
    	*/
    	private static function getFileData($filepath){
    		if (!$filepath) {
    			return '';
    		}
    		$content = '';
    		$fp = fopen($filepath, 'rb');
    		while (!feof($fp)) {
    			$content .= fread($fp, 1024);
    		}
    		return $content;
    	}
    	private static function getHost(){
    		return self::$host;
    	}
    	private static function setHost(){
    		self::$host = $host;
    	}
    	private static function getQuery(){
    		return self::$query;
    	}
    	private static function setQuery(){
    		self::$query = $query;
    	}
    	private static function getHeaders(){
    		return self::$headers;
    	}
    	private static function setHeaders(){
    		self::$headers = $headers;
    	}
    }

     

    展开全文
  • 第一、安装邮件发送工具mailx 这里我选择的是mailx,所以的关闭其他的邮件发送工具 service sendmailstop #关闭 chkconfig sendmailoff #禁止开机启动 service postfixstop chkconfig postfixoff 执行安装...
  • 邮件发送工具是好多年前就开源出来的,核心就是调用最底层socket通信来实现的邮件发送程序,以前用C#写过,微软都封装好的,不知道底层是如何实现的,只知道调用方法,这次用C++实现了下,参考了很多网上的例子。...
  • kali 下的邮件发送工具 swaks Swaks 是一个功能强大,灵活,可编写脚本,面向事务的 SMTP 测试工具,目前 Swaks 托管在私有 svn 存储库中。 官方项目 http://jetmore.org/john/code/swaks/ 1.测试邮箱的连通性 ...
  • java邮件发送工具

    2019-05-03 01:32:23
    NULL 博文链接:https://davidhhs.iteye.com/blog/2431043
  • QT编写的邮件发送工具可执行文件

    热门讨论 2014-03-12 19:36:29
    项目名称:邮件发送工具 开发环境:XP+QT4.7+QT CREATOR2.8+MINGW 已编译通过测试平台:XP、Win7、ubuntu、tiny210、TE6410 技术实现:通过socket通信实现smtp协议,根据应答解析协议并作出处理发送邮件 基本功能: ...
  • 一、前言邮件发送工具是好多年前就开源出来的,核心就是调用最底层socket通信来实现的邮件发送程序,以前用C#写过,微软都封装好的,不知道底层是如何实现的,只知道调用方法,这次用C++实现了下,参考了很多网上的...
  • 支持163邮箱发送桌面简洁版 1,更新收件地址为任意邮箱地址 2,增加邮件群发功能,多个收件地址用英文(,)逗号隔开 3,修复链接出错问题.
  • NULL 博文链接:https://conkeyn.iteye.com/blog/924126
  • Java MailUtils邮件发送工具类 支持附件JavaMail Demo,引用的jar如下: - activation.jar - mail.jarsmtp设置参考https://www.west.cn/faq/list.asp?Unid=852示例代码package com.alexli.uitl; import java.util....

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,362
精华内容 1,744
关键字:

邮件发送工具