问题描述
我想使用以下方法向多个收件人发送邮件::
I want to send message to multiple Recipients using following method ::
message.addRecipient(Message.RecipientType.TO, String arg1);
或
message.setRecipients(Message.RecipientType.TO,String arg1);
但有一个混淆是在第二个争论中,
如何传递多个地址,如: / p>
But one confusion is that in Second arguement,How to pass multiple addresses like :
message.addRecipient(Message.RecipientType.CC, "[email protected],[email protected],[email protected]");
或
message.addRecipient(Message.RecipientType.CC, "[email protected];[email protected];[email protected]");
我也可以使用替代方法发送消息,但想知道上述方法的目的。
如果我无法使用它(至于现在我没有得到上述要求的任何答案)那么这个方法需要在邮件API中。
I can send message using alternate methods too, but want to know the purpose of above method.If i cant use it(as till now i haven't got any answer for above requirement) then what is the need for this method to be in mail API.
推荐答案
如果多次调用 addRecipient
,它会将给定的收件人添加到给定时间的收件人列表中(TO, CC,BCC)
If you invoke addRecipient
multiple times it will add the given recipient to the list of recipients of the given time (TO, CC, BCC)
例如:
message.addRecipient(Message.RecipientType.CC, InternetAddress.parse("[email protected]"));
message.addRecipient(Message.RecipientType.CC, InternetAddress.parse("[email protected]"));
message.addRecipient(Message.RecipientType.CC, InternetAddress.parse("[email protected]"));
将3个地址添加到CC
Will add the 3 addresses to CC
如果您希望一次添加所有地址,您应该使用 setRecipients
或 addRecipients
并为其提供一组地址
If you wish to add all addresses at once you should use setRecipients
or addRecipients
and provide it with an array of addresses
Address[] cc = new Address[] {InternetAddress.parse("[email protected]"),
InternetAddress.parse("[email protected]"),
InternetAddress.parse("[email protected]")};
message.addRecipients(Message.RecipientType.CC, cc);
您还可以使用 InternetAddressAddress.parse
解析地址列表
message.addRecipients(Message.RecipientType.CC,
InternetAddress.parse("[email protected],[email protected],[email protected]"));
这篇关于在Java中将邮件发送给多个收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!