使用mail.jar和activation.jar发送所需的邮件内容
我使用mail.jar和activation.jar作为类路径,并编写了自动邮件发送功能,并且工作正常。
在我的程序中,内容被声明为字符串。但我的要求是,我需要从 SQL DB 的不同表中检索一些计数,并将其附加到邮件内容中。
我认为将内容声明为 String 不会帮助我完成任务,因为我将在邮件内容中发送的行数将超过五六行。
请告诉我如何将大文本添加到邮件内容中。任何类型的链接或教程来证明其合理性都将非常值得赞赏。提前非常感谢..祝大家周日快乐..!!
Am using mail.jar and activation.jar as classpath and have programmed a automatic mail sending and it works fine.
In my program, the content is declared as a String. But my requirement is, I need to retrieve few of the counts from different tables of my SQL DB and attach the same in my content of the mail.
I think declaring the content as String will not help me out to achieve the task since the number of lines that I will be sending in the content of the mail will be more than five or six.
Kindly let me know how a large text can be added to the content of the mail. Any sort of links or tutorials for justifying the same will be highly appreciable. Thanks a lot in advance.. Happy Sunday guys.. !!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能熟悉 System.out.println 等...您可以使用此方法打印到如下字符串:
上面的代码片段将(在最后一个 System.out.println 中) out.println-call) print:
这样您就可以使用
println
-方法调用轻松构建电子邮件消息字符串。You're probably familiar with
System.out.println
etc... You can use this method to print to a string like this:The above snippet of code would (in the last
System.out.println
-call) print:This way you could easily construct an email message string using
println
-method calls.如果您只需要发送几行而不是一行,您仍然可以使用单个字符串。一个字符串可以容纳多行文本。只需在必要时添加换行符即可。
实际上假设您的邮件正文是纯文本格式,您应该使用 CR LF 作为行终止符(每行末尾的
\r\n
)。所以你可以像这样构建你的内容:
If you simply need to send a few lines instead of one, you can still use a single String. A String can hold multiple lines of text. Just add newlines where necessary.
Actually assuming your mail body is in plain text format, you should use CR LF as a line terminator (
\r\n
at the end of each line).So you can build your content like this:
查看 [链接文本][1] 以动态地将参数与字符串合并。您可以考虑将文本作为资源从类路径加载,而不是静态字符串。
[1]: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...)
Check out [link text][1] for dynamically merging parameters with a String. Instead of a static String you could consider loading the text as a resource from the classpath.
[1]: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...)