Smtp 如何使用Java Mail API发送大于25 MB的文件

Smtp 如何使用Java Mail API发送大于25 MB的文件,smtp,gmail,java,Smtp,Gmail,Java,我正在设计一个应用程序,使用Gmail的smtp主机发送带有附件的电子邮件。但是,当文件大于25MB时,我会收到一个错误,即“552-5.2.3您的邮件超出了Google的邮件大小限制。请访问查看我们的邮件大小指南。 188sm2692677pfg.11-gsmtp 最终字符串用户名=”username@gmail.com"; 最终字符串password=“password”; Properties prop=新属性(); prop.put(“mail.smtp.host”、“smtp.gmai

我正在设计一个应用程序,使用Gmail的smtp主机发送带有附件的电子邮件。但是,当文件大于25MB时,我会收到一个错误,即“552-5.2.3您的邮件超出了Google的邮件大小限制。请访问查看我们的邮件大小指南。 188sm2692677pfg.11-gsmtp

最终字符串用户名=”username@gmail.com";
最终字符串password=“password”;
Properties prop=新属性();
prop.put(“mail.smtp.host”、“smtp.gmail.com”);
prop.put(“mail.smtp.port”,“587”);
prop.put(“mail.smtp.auth”,“true”);
prop.put(“mail.smtp.starttls.enable”,“true”);
Session Session=Session.getInstance(prop,
新的javax.mail.Authenticator(){
受保护的密码身份验证getPasswordAuthentication(){
返回新密码身份验证(用户名、密码);
}
});
试一试{
Message Message=新的mimessage(会话);
message.setFrom(新的InternetAddress(“username@gmail.com"));
message.setRecipients(
Message.RecipientType.TO,
InternetAddress.parse(“接收方地址”);
message.setSubject(“此邮件是测试邮件”);
BodyPart messageBodyPart=新的MimeBodyPart();
messageBodyPart.setText(“消息”);
Multipart Multipart=新的MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart=新的MimeBodyPart();
字符串文件名=;
DataSource source=新文件DataSource(文件名);
setDataHandler(新的DataHandler(源));
messageBodyPart.setFileName(文件名);
multipart.addBodyPart(messageBodyPart);
message.setContent(多部分);
传输。发送(消息);
}捕获(消息异常e){
showMessageDialog(null,e.getMessage());
}
有没有办法发送超过gmail 25MB限制的文件?
我可以从帐户设置更改文件大小上载限制吗?或者我可以做一些类似于任何文件都将作为驱动器链接上载的事情吗?

否。这是硬限制。Gmail本身声明:

如果您的文件大于25MB,Gmail会自动在电子邮件中添加一个谷歌硬盘链接,而不是将其作为附件

这也是我给你的建议,把文件上传到某个地方,然后在邮件中粘贴一个链接。选项可能是:谷歌硬盘,Mega,Dropbox,S3


除此之外,您无能为力。

用户友好的方式可能是将文件上载到某个位置,并在邮件中添加指向该文件的链接

还可以将文件拆分为几个较小的部分,并在各自的邮件中发送每个部分。然后,收件人需要再次将这些文件连接在一起

Zip归档程序通常可以将大文件拆分为多个Zip文件,然后再将这些文件连接在一起

还有原始的拆分和连接。我还没有见过操作系统发行版中内置的标准拆分命令。但是你的程序可以按你想要的任何方式分割文件


在Windows或Unix(Linux和其他)操作系统下,加入这些文件非常容易。在Windows中,您转到命令提示符并使用“copy”:
copy file1+file2+file3 finalfile
在Unix中,您使用“cat”:
cat file1 file2 file3>finalfile

我认为这是谷歌方面的一个限制,而不是javaSize限制是由谷歌和更多电子邮件客户端设置的,请看一看
    final String username = "username@gmail.com";
    final String password = "password";

    Properties prop = new Properties();
    prop.put("mail.smtp.host", "smtp.gmail.com");
    prop.put("mail.smtp.port", "587");
    prop.put("mail.smtp.auth", "true");
    prop.put("mail.smtp.starttls.enable", "true");

    Session session = Session.getInstance(prop,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("username@gmail.com"));
        message.setRecipients(
                Message.RecipientType.TO,
                InternetAddress.parse("receiver address"));
        message.setSubject("This mail is a test mail");
     BodyPart messageBodyPart = new MimeBodyPart();  
     messageBodyPart.setText("Message");


     Multipart multipart = new MimeMultipart();


     multipart.addBodyPart(messageBodyPart);


     messageBodyPart = new MimeBodyPart();
     String filename = <Path>;
     DataSource source = new FileDataSource(filename);
     messageBodyPart.setDataHandler(new DataHandler(source));
     messageBodyPart.setFileName(filename);
     multipart.addBodyPart(messageBodyPart);

     message.setContent(multipart);

        Transport.send(message);


    } catch (MessagingException e) {
        JOptionPane.showMessageDialog(null, e.getMessage());
    }