SendFailedException: Invalid Addresses - but there is no invalid addresses in the exception - jakarta-mail

I'm trying to send a message to multiple recipients. I'm doing pretty standard thing:
Properties p = new Properties();
p.setProperty("mail.smtp.host", "my.smtp.host");
Session session = Session.getInstance(p);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(origin));
msg.setReplyTo(new InternetAddress[]{ new InternetAddress(replyTo) });
for( String address : destinations ) {
msg.addRecipient(Message.RecipientType.BCC, new InternetAddress(address));
}
msg.setSubject("foo");
msg.setText("bar");
msg.setSentDate(new Date());
Transport.send(msg);
Most times it works, a few times it doesn't. The exception I get is SendFailedException: Invalid Addresses. When I print the contents of the exception I get this:
-ivalid:[]
-valid unsent:[...#gmail.com, ...#hotmail.com, ...#live.com, ...]
-valid sent:null
Basically it says there is one or more invalid addresses and then it says there is no invalid address. Shouldn't the invalid addresses array have at least one email address?
UPDATE
The SendFailedException is caused by another exception with the following message:
451 4.3.0 <sender_email_address>: Temporary lookup failure
Maybe the invalid address in the message is not from any of the recipients but from the sender.

It doesn't look like you're authenticating to your mail server, so it's probably not letting you send to non-local addresses. (Yes, the error message isn't very helpful in this case.)

Related

Regarding connection class in RethinkDb

I am not able to understand why am I getting this error stating that connection of type Connection is not initialized if anyone could help me out with it.
enter image description here
In your main method, you are writing
Connection connection; // connection is still null
UserService sut = UserService(r, connection);
But as you error message said : you cannot instantiate UserService with a connection variable that is null.
You must rework your code so your variable won't be null when you initialize the UserService

NpgsqlConnection : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

I am getting error 'Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.' when connecting to PostgreSQL db from .net console application. As far as I did R&D and tried different things, I found that it may be because of = in password as other connection string works fine that doesn't have = in password. Is there any way to pass = in password tried sending %3D instead of = but it didn't work. Password is abc=xyz. Issue looks like with Password=abc=xyz, tried changing it to Password=abc%3Dxyz as well. pgcon.Open(); gives this error.
string pgconnectionstring="Server=someserver.azure.com;Username=dev#postgres;Database=dbname;Port=5432;Password=abc=xyz;SSLMode=Require";
using (NpgsqlConnection pgcon = new NpgsqlConnection(pgconnectionstring))
{
pgcon.Open();
}
NpgsqlConnection doesn't have property password to be set from outside, Is there any way to handle = or other special chars or set password differently?
Issue was not because of =, It was because of DB name. Seems like DB name should be case sensitive. The actual db name is Field-Service. And I was setting it like Field-service, s in small which led to the issue. Though exception message led to wrong direction as it gave error connection closed by remote which generally comes in case of wrong password instead should have given something like DB doesn't exists.

Camel Idempotent Consumer incorrect behaviour for removeOnFailure=true

I would like to know if the below is expected behaviour for Camel idempotent consumer:
I have removeOnFailure=true for the route, which means basically when the exchange fails idempotent consumer should remove the Identifier from the repository. This brings up a very interesting scenario which allows duplicate on the exchange.
Suppose I have identifier=12345 and first attempt to execute the exchange was Succesfull which means identifier is added to idempotent repository. Next attempt to use same identifier i.e 12345 fails as this is caught as Duplicate Message (CamelDuplicateMessage). But at this point having removeOnFailure=true will remove the identifier from the repository which on next attempt will allow the exchange to go through successfully without catching the default message. Hence, creating a room for duplication on the exchange.
Can someone advise if this is expected behaviour or some bug?
Sample Route:
from("direct:Route-DeDupeCheck").routeId("Route-DeDupeCheck")
.log(LoggingLevel.DEBUG, "~~~~~~~ Reached to Route-DeDupeCheck: ${property.xref}")
.idempotentConsumer(simple("${property.xref}"), MemoryIdempotentRepository.memoryIdempotentRepository()) //TODO: To replace with Redis DB for caching
.removeOnFailure(true)
.skipDuplicate(false)
.filter(exchangeProperty(Exchange.DUPLICATE_MESSAGE).isEqualTo(true))
.log("~~~~~~~ Duplicate Message Found!")
.to("amq:queue:{{jms.duplicateQueue}}?exchangePattern=InOnly") //TODO: To send this to Duplicate JMS Queue
.throwException(new AZBizException("409", "Duplicate Message!"));
Your basic premise is wrong.
Next attempt to use same identifier i.e 12345 fails as this is caught
as Duplicate Message (CamelDuplicateMessage)
When there is a duplicated message, it is not considered as a failure. It is just ignored from further processing(unless you have skipDuplicate option set to true).
Hence the scenario what you just explained cannot occur what so ever.
It is very easy to test. Considering you have a route like this,
public void configure() throws Exception {
//getContext().setTracing(true); Use this to enable tracing
from("direct:abc")
.idempotentConsumer(header("myid"),
MemoryIdempotentRepository.memoryIdempotentRepository(200))
.removeOnFailure(true)
.log("Recieved id : ${header.myid}");
}
}
And a Producer like this
#EndpointInject(uri = "direct:abc")
ProducerTemplate producerTemplate;
for(int i=0, i<5,i++) {
producerTemplate.sendBodyAndHeader("somebody","myid", "1");
}
What you see in logs is
INFO 18768 --- [tp1402599109-31] route1 : Recieved id : 1
And just once.

CXF's readEntity() got "Entity is not available"

I am working on a piece of code that uses CXF (3.1.2)
I am seeing this error intermittently:
java.lang.IllegalStateException: Entity is not available
at org.apache.cxf.jaxrs.impl.ResponseImpl.checkEntityIsClosed(ResponseImpl.java:481)
at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:333)
at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(ResponseImpl.java:320)
at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity(ResponseImpl.java:310)
To improve performance, the Response objects are held through a Google Guava LoadingCache (com.google.common.cache.LoadingCache). It seems like I would get this error after an object has been in the cache for a few minutes. Could the Response object because invalid
after a few minutes?
private static LoadingCache<String, Response> cachedLdapRespMap
= CacheBuilder.newBuilder()
.maximumSize(Constants.LDAP_RESP_CACHE_SIZE)
.expireAfterWrite(Constants.LDAP_RESP_CACHE_KEEP_ALIVE_MINUTE
, TimeUnit.MINUTES)
.build(
new CacheLoader<String, Response>() {
#Override
public Response load(String uid)
throws Exception {
Response res = makeLdapRequest(uid);
return res;
}
}
);
(I am answer the question myself)
The problem was that I have concurrent processes that attempted to readEntity(), the first process consumed the input stream (or may have even closed the stream), and the second process would either get thrown an IllegalStateException or got an empty message. Here is what the JavaDoc of javax.ws.rs.core.Response (which org.apache.cxf.jaxrs.impl.ResponseImpl extends) says:
Throws:
IllegalStateException - if the entity is not backed by an
input stream, the response has been closed already, or if the entity
input stream has been fully consumed already and has not been buffered
prior consuming.
So to fix the problem, I changed my design to cache not the Response object but rather the string message that is the result of the readEntity() call. The call would be done exactly once when the response comes back:
Response resp ...
String respStr = resp.readEntity(String.class);
and the problem is solved.

Error While sending mails using Java Mail

I am getting the following error while sending mails using Java Mail.
Below is the error. Could you please let me know the causes on the error.
ERROR :: Sending failed;
nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
nested exception is:
class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
nested exception is:
class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
nested exception is:
class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
nested exception is:
class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
nested exception is:
class javax.mail.SendFailedException: 452 Too many recipients received this hour
;
nested exception is:
class javax.mail.SendFailedException: 452 Too many recipients received this hour
Below is the method causing Exception.
public void sendTextReport(DataBean dataBean, TextBean textBean) throws IOException, MessagingException {
Session session = getAuthentication();
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(this.props.getProperty("from")));
message.addRecipients(Message.RecipientType.TO,InternetAddress.parse(this.props.getProperty("textTo")));
message.addRecipients(Message.RecipientType.CC,InternetAddress.parse(this.props.getProperty("textCc")));
message.setSubject(" Report for the submissions between "+ dates.getDate1() + " and " + dates.getDate2());
StringBuilder mailBody = new StringBuilder();
mailBody.append("<text>Hi All,<br><br>Below is the Report for the submissions </text><br><br><br>");
mailBody.append("<table><tr><th>Description</th><th>Count</th></tr>");
LinkedHashMap map=(LinkedHashMap) getTextMap(dataBean,textBean);
Iterator it=map.entrySet().iterator();
while(it.hasNext()){
Entry<String, Integer> entry=(Entry) it.next();
mailBody.append("<tr><td>"+entry.getKey()+"</th><td class='count'>"+entry.getValue()+"</td></tr>");
}
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setContent(mailBody.toString(), "text/html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart1);
message.setContent(multipart);
Transport.send(message);
}
public Session getAuthentication() {
final String host = this.props.getProperty("from");
final String password = this.props.getProperty("password");
properties.setProperty("mail.smtp.host", this.props.getProperty("hostName"));
Session session = Session.getInstance(properties,null);
return session;
}
textTo: This string contains 3 email addresses
textCc: this String contains 1 Distribution list which has 8 email addresses.
All are valid email addresses. I checked with getValidUnsentAddresses() in SendFailedException.Seems all are valid but not sent.
This is called grey-listing. When you send too many e-mails (or more often - a certain number of e-mails where a recipient does not exist) a destination mail server does not black list you, but instead they temporarily block access from your mail server (essentially the IP address of your mail server). Usually this block is set for 1 hour but obviously can vary depending on the configuration.
You can do several things:
1.Contact the admins of the domain in question (e.g. postmaster#messaging.sprintpcs.com) and request your IP address to be whitelisted. (They may refuse).
2.Check/increase time e-mails can stay in your local queues (to have more chances of them to retry and finally get delivered.
3.Add more public IP addresses to your server

Resources