Java sends mail through Tencent Enterprise Mailbox

Java Send mail through Tencent Enterprise Mailbox

  1. 企业邮箱 requires ssl

    @private static String account = "Enterprise Email Account"; // Login Account
    Private static String password = "Enterprise Email Password"; // Login Password
    Private static String host = "";// server address
    Private static String port = "465";// port
    Private static String protocol = "smtp";// protocol
    //Initialization parameters
    Public static Session initProperties() {
        Properties properties = new Properties();
        properties.setProperty("mail.transport.protocol", protocol);
        properties.setProperty("", host);
        properties.setProperty("mail.smtp.port", port);
        // Use smtp authentication
        Properties.put("mail.smtp.auth", "true");
        / / Use SSL, corporate mailbox must start
        // Turn on the security protocol
        MailSSLSocketFactory mailSSLSocketFactory = null;
        Try {
            mailSSLSocketFactory = new MailSSLSocketFactory();
        } catch (GeneralSecurityException e) {
        Properties.put("mail.smtp.enable", "true");
        Properties.put("mail.smtp.ssl.socketFactory", mailSSLSocketFactory);
        Properties.put("mail.smtp.socketFactory.class", "");
        Properties.put("mail.smtp.socketFactory.fallback", "false");
        Properties.put("mail.smtp.socketFactory.port", port);
        Session session = Session.getDefaultInstance(properties, new Authenticator() {
            Protected PasswordAuthentication getPasswordAuthentication() {
                Return new PasswordAuthentication(account, password);
        / / Use SSL, corporate mailbox required end
        // TODO displays the debug information. The official environment is commented out.
        Return session;
    @param sender sender alias
    @param subject mail subject
    @param content Email content
    @param receiverList Receiver list, separated by "," between multiple recipients
    @param fileSrc attachment address
    Public void send(String sender, String subject, String content, String receiverList, String fileSrc) {
        Try {
            Session session = initProperties();
            MimeMessage mimeMessage = new MimeMessage(session);
            mimeMessage.setFrom(new InternetAddress(account, sender));// Sender, you can set the sender's alias
            // recipient, multi-person reception
            InternetAddress[] internetAddressTo = new InternetAddress().parse(receiverList);
            mimeMessage.setRecipients(Message.RecipientType.TO, internetAddressTo);
            // theme
            // time
            mimeMessage.setSentDate(new Date());
            // container class attachment
            MimeMultipart mimeMultipart = new MimeMultipart();
            // can wrap text, images, attachments
            MimeBodyPart bodyPart = new MimeBodyPart();
            / / Set the content
            bodyPart.setContent(content, "text/html; charset=UTF-8");
            // Add image & attachments
            bodyPart = new MimeBodyPart();
        } catch (MessagingException e) {
        } catch (UnsupportedEncodingException e) {
        } catch (IOException e) {