将邮件从GCLOUD发送到其他电子邮件(gmail,yahoo)。像电子邮件验证链接,订阅确认

时间:2016-03-15 12:25:12

标签: email cloud javamail google-compute-engine gcloud-java

     import java.util.*;  
import javax.mail.*;  
import javax.mail.internet.*;  
import javax.activation.*;  

public class SendEmail  
{  
 public static void main(String [] args){  
      String to = "gourab.p17@gmail.com";

      String from = "gp@sharenodes.com";
      String host = "localhost";//or IP address  


      Properties properties = System.getProperties();  
      properties.setProperty("mail.smtp.host", host);  


      Session session = Session.getDefaultInstance(properties);  

      try{  
         MimeMessage message = new MimeMessage(session);  
         message.setFrom(new InternetAddress(from));  
         message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));  
         message.setSubject("Ping");  
         message.setText("Hello, this is example of sending email  ");  

         // Send message  
         Transport.send(message);  
         System.out.println("message sent successfully....");  

      }catch (MessagingException mex) {mex.printStackTrace();}  
   }  
}  

我不想去sendgrid / google-email-api / mailgun 我已经映射了DNS-A(主机)@ 23.236.49.96 600秒sharenodes.com 但是无法发送邮件。尝试过properties.put(“mail.smtp.port”,“2525”); 但没有邮件收到任何错误。对于端口25,465,587,它会因谷歌阻止这些端口而引发错误

1 个答案:

答案 0 :(得分:0)

Google Compute Engine不允许端口25,465和587上的出站连接。话虽如此,您可以在未被Compute Engine阻止的任何端口上设置您自己的电子邮件服务器,也可以使用SendGrid等合作伙伴服务,Mailgun或使用Google Apps。这些信息记录在link