【问题标题】:How to include a table within an email [duplicate]如何在电子邮件中包含表格[重复]
【发布时间】:2013-06-13 05:25:03
【问题描述】:

我想自动发送一封电子邮件。我在 struts 框架的帮助下实现了这个东西。我需要发送一封电子邮件,其中将包含特定门户的 URL,并且电子邮件正文应包含一个包含两列但行数不固定的表格。

【问题讨论】:

  • 和 HTML 一样
  • 以 html 格式发送?怎么做 -> stackoverflow.com/questions/5068827/…
  • 你能告诉我们what you have tried到目前为止,除了问我们吗?
  • 在 JavaMail 中,我通过在用户客户端 (Thunderbird) 中创建邮件、查看源代码并将其转移到我的项目中来作弊。也许它也是适合您的解决方案。干杯!
  • 你能上传你的代码吗?

标签: java email


【解决方案1】:

您的电子邮件可以是 HTML 电子邮件。因此,您将使用 HTML 来实现表格,并相应地设置电子邮件 mime 类型标题。

This answer告诉你如何正确设置mime类型。

【讨论】:

    【解决方案2】:

    首先以字符串格式创建您的table,然后将该字符串设置为setMsg()

     MultiPartEmail htmlEmail = new HtmlEmail();
    
            email.setSmtpPort(getPortNumber());
            // authenticating the user
            email.setAuthenticator(new DefaultAuthenticator(getSenderID(),
                    getSenderPassword()));
            // email.setDebug(true);
            email.setSSL(true);
            //
            email.setTLS(true);
            // setting the host name
            email.setHostName(getHostName());
            // setting the rciever id
    
            email.addTo(receiverId);
            email.setFrom(getSenderID());
                // setting the subject of mail
            email.setSubject(getSubject());
            email.setMsg("<table border="1"><tr><td></td></tr>");//here is your html code
            email.send();
    

    【讨论】:

    • 感谢你们的快速响应。我在我的动作类方法中使用了一个while循环,并将该表包含在该while循环中。我创建的表是消息正文中的简单html代码。
    猜你喜欢
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多