尝试将邮件发送到动态电子邮件ID时出错

时间:2013-01-22 09:12:30

标签: java android javamail sendmail

我必须使用javamailapi应用程序开发一个android发送邮件。

message.setRecipients(Message.RecipientType.TO,
                        InternetAddress.parse("mercy.krishnaveni@gmail.com,demo@mercuryminds.com"));

使用上述代码邮件将发送给收件人 但是现在我想发送其ID写在以下字符串中的邮件。

 string Email="mercy.krishnaveni@gmail.com"
 message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("Email,demo@mercuryminds.com"));

当我使用上面的代码时,邮件没有正确发送,它给了我以下错误:

01-22 07:13:31.609: E/AndroidRuntime(959): FATAL EXCEPTION: main
01-22 07:13:31.609: E/AndroidRuntime(959): java.lang.RuntimeException: javax.mail.SendFailedException: Invalid Addresses;
01-22 07:13:31.609: E/AndroidRuntime(959):   nested exception is:
01-22 07:13:31.609: E/AndroidRuntime(959):  com.sun.mail.smtp.SMTPAddressFailedException: 553-5.1.2 We weren't able to find the recipient domain. Please check for any
01-22 07:13:31.609: E/AndroidRuntime(959): 553-5.1.2 spelling errors, and make sure you didn't enter any spaces, periods,
01-22 07:13:31.609: E/AndroidRuntime(959): 553 5.1.2 or other punctuation after the recipient's email address. ni8sm10202402pbc.70

请帮我解决我的错误,以及如何发送电子邮件????

1 个答案:

答案 0 :(得分:1)

我认为你需要更换

message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("Email,demo@mercuryminds.com"));

message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(Email+",demo@mercuryminds.com"));

找不到电子邮件地址,因为它试图找到“电子邮件”而不是电子邮件的价值(“mercy.krishnaveni@gmail.com”)。

希望有所帮助,