In the meteor email documentation it is written
Email.send({
to: to,
from: from,
subject: subject,
text: text
});
Send an email. Throws an Error on failure to contact mail server or if
mail server returns an error
Should I assume this is done synchronously on the server side and that I should use a try/catch statement in order to know if the mail did sent successfully ? If so then I would have to assume that no catch means no error ?
Well you've answered this yourself:
It is sychronous
You would use try/catch in the case the mail server returns an error (if you've set MAIL_URL)
No catch means no error, again provided you've set MAIL_URL as the environmental variable.
Related
I'm new in mirth so sorry if my question may seems naive.
I've a mirth channel that recives hl7 messages, and this is fine, also I've some filters and transformers both in Source and Destination.
When all is fine at the end of destination I send an ACK with a message, for this for this purpose I've made this function in code Templates:
function getAck(success, detailMessage, statusMessage) {
if (!detailMessage)
detailMessage = success ? "Operation completed successfully" : "Some error occours";
if(!statusMessage)
statusMessage = detailMessage;
if (success) {
ack = ACKGenerator.generateAckResponse(connectorMessage.getRawData(), "AA", detailMessage);
resp = new Response(com.mirth.connect.userutil.Status.SENT, ack, statusMessage);
} else {
ack = ACKGenerator.generateAckResponse(connectorMessage.getRawData(), "AE", detailMessage);
resp = new Response(com.mirth.connect.userutil.Status.ERROR, ack, statusMessage, detailMessage);
}
return resp;
}
So I use ACKGenerator.generateAckResponse for creating an Ack and Response for send response at client. This work but only in destination and that's my problem.
If I get an error before destination (e.g. in filters, transformer, ...) I don't be able to stop execution and send an NACK with an explaination of the error and this is what I would like to do.
Am I wrong doing things in this way?
You can store a Response in the responseMap in any filters or transformers. Once you define a key in the responseMap, it should be available as a selection in the response drop down on the source tab of your channel (instead of picking a destination.)
Your current connector should stop processing a message with an ERROR status if you manually throw an exception after setting the desired value in the responseMap. If you are in a filter, you could also filter the message instead of throwing the exception.
If you are worried about an uncaught exception, you could initialize the responseMap variable with an "Unknown Error" message at the first point in the channel where your custom code is defined that affects messages directly (likely the source filter from your description, but could possibly be the pre-processor or attachment handler if you use those.) The expectation is that this would be replaced with a more descriptive error or a success if the message makes it all the way through to the end, but the channel will always have something to return.
There are filter and transformer in the "Source" tab. If your expecting an error there or on other destinations, you could try:
Adding a try-catch code block in your filter and transformer.
Use your custom code template function in your filter and transformer to catch the error or issue.
Create a separate channel that will receive the ACK/NACK which will be responsible in forwarding that message to the client.
In your try-catch code block or custom code template, use the method router.routeMessageByChannelId to forward the ACK/NACK to the other channel (step 3).
Note: You'll need to disable the default response in your original channel since you have the other channel that'll forward the ACK/NACK. You'll also need to consider if the client's machine expects a valid ACK/NACK immediately when they sent the HL7 message, depends on their setup.
In RFC 821, it says that a reset (RSET) command can be sent after a DATA command and some mail data has been sent:
However, what distinguishes between a mail client sending an RSET command after DATA, and a mail that contains the word "RSET" on a line by itself?
I've checked RFC 5321 as well and I can't see anything that would mitigate or escape this. It does talk about escaping a mail line which starts with a ".", but not "RSET".
The client cannot terminate the mail data transfer with a period on a line by itself or the server will send the partial mail it has been given.
I imagine there's something I've missed in the RFCs, otherwise I can't help thinking that there's either an SMTP command injection attack vector in many implementations, or no-one can ever send a mail with "RSET" on a line by itself (I think people would have noticed).
The keyword here is after I believe. The DATA command is in progress until it is finished with a lone . on a line.
RFC 5321 § 4.1.1.5 (RSET) states "any stored sender, recipients, and mail data MUST be discarded." This refers to the MAIL FROM, RCPT TO, and presumably DATA commands.
However, upon receiving the . following DATA, the message "MUST" be delivered (which may result in a failure but not a partial failure, see § 4.1.1.4). This clears the buffer of everything RSET is supposed to do.
This means RSET merely elicits a 250 OK response from the receiving server (a keep-alive, much like NOOP) and confirms to the sender that there is indeed no saved sender or recipient queued for the next message.
I do not know of a way to interrupt a DATA command to issue a RSET. The only way I know of to do that is to terminate the connection and establish a new one—and, just to be safe in the case of some odd resumption capability, I'd issue an RSET right after the EHLO or HELO (which the spec says is a NOOP). If there were such a way, it should be in RFC 5321 § 4.1.1.4, § 4.1.1.5, and/or § 3.3.
I use fetchmail to retrieve email from an IMAP server every five minutes, passing it to a local postfix process for delivery. The problem: sometimes an email has an invalid "From" line (usually spam), like this one with a leading hyphen:
From: "- Some Dumb Spammer" <-DumbSpammer#example.com>
In this case, fetchmail retrieves the email and passes it to my local postfix process, which raises an error:
fetchmail: SMTP error: 501 5.1.7 Bad sender address syntax
This error causes fetchmail to leave the bad email sitting on the IMAP server, even when my .fetchmailrc file says nokeep. As a result, fetchmail re-downloads it every five minutes. Repeat forever... or until I manually delete the bad email from the IMAP server.
What's the best way to break these loops automatically, either deleting or delivering the bad email, without opening a security hole (e.g., permitting leading hyphens)? Thank you.
The kind people on the fetchmail-users mailing list answered my question. To summarize their response, you can use fetchmail --nosoftbounce to permanently delete undeliverable messages, use the antispam option to accept the emails (fetchmail -Z 501), or configure postfix to permit leading hyphens if it's safe to do so. The options are documented on the fetchmail man page.
Remove Asp TAG username 'admin#seudominio.com.br' == admin#seudominio.com.br:
#!/bin/sh
set logfile '/var/log/fetchmaillog'
set no bouncemail
defaults fetchall
poll locapack.com.br with protocol pop3
username admin#seudominio.com.br password xxxx is admin#seudominio.com.br here;
I am using mailparser by andris(https://github.com/andris9/mailparser). I am sending an email via redis to an nodejs app. The mailparser for somereason is unable to parse it. What could be causing the issue?
The code to get the email from redis. client is an instance of node_redis Client. MailParser is andris' mailparser. The email in redis is sent via another server, to whose channel i have subscribed. The email sent, when saved in a text file and parsed using andris' test.js, gives the expected output.
client.subscribe('email1');
client.on('message', function(channel, message){
var Parser = new MailParser();
Parser.on('headers', function(headers){
console.log(headers.addressesTo[0].address);
});
Parser.feed(message);
Parser.end();
});
I found the reason for this. The input I saw receiving had \r\n converted to \n
Instead of
Parser.feed(message);
I believe you want
Parser.write(message);
I couldn't find the feed method in the documentation. I am using the write function and it's working. The message is the original unaltered email message, including headers, body, and attachments.
Is it possible to catch a MailException when sending an e-mail?
I want to catch it in scenarios like mail server is down, malformed e-mail address, etc.
I see the MailException in the console but I cannot catch it when I call Mailer.send(). The Mailer.send() sends the e-mail asynchronously and thus I cannot catch the exception. How can I wait for the result suspending the HTTP request?
Another question: Does the Mailer.sendAndWait() suspend the request?
First the mail() method might throw a MailException if sending mail fails.
The send methods return a Future of type Boolean, if you call get() on the future you will get the result of the mail sending, mind that this call is blocking and will wait for the mail sending to finish.
This is the same thing as using sendAndWait()
This get can also throw an ExecutionException but I don't have the impression this is used by the play mailer. Instead you get back false from the future and the exception is logged.
SendAndWait() does not suspend the request as far as I can see in the sources
more info here:
http://download.oracle.com/javase/1,5.0/docs/api/java/util/concurrent/Future.html
https://github.com/playframework/play/blob/master/framework/src/play/mvc/Mailer.java
https://github.com/playframework/play/blob/master/framework/src/play/libs/Mail.java