I noticed the Opa API has a SMTPServer extension. I'm not entirely sure how this is to be used. Is what functions of email parsing built in and which have to be written in the handler? I'd appreciate a "hello world" style example for this extension.
Asked
Active
Viewed 89 times
1 Answers
2
This code snippet should help you. It is extracted from the code behing http://forum.opalang.org reply-by-email feature:
function convert_to_utf8(s, b) {
match (Iconv.convert_to_utf8(s, b)) {
case { some : s }: s
default: log_error("..."); ""
}
}
function raw_handler(to, content) {
...
message = Mime.parse(content);
match (message) {
case { some : content }:
content = Mime.get_text(content, convert_to_utf8);
....
default: void
...
}
function handler(string from, list(string) to, string raw_content) {
List.fold({
function(to, acc) _ = raw_handler(to, raw_content); acc
}, to, {success})
}
SmtpServer.start(0.0.0.0, 2525, {none}, handler)

Cédrics
- 1,974
- 11
- 13
-
Explains things a lot better. I seem unable to send an email to it with this error: 450 4.1.8
: Recipient address rejected: Domain not found – eyecreate Oct 01 '12 at 13:52 -
how did you configure the smtp sever in your mail app? is the port correct? are you testing locally? is localhost reachable on your machine (`ping localhost`)? – Cédrics Oct 05 '12 at 08:21
-
Configured same as your example with handler name changed.(and obviously handler code diff) Sending mail locally using sendemail. It is reachable and connects, but rejects the email. – eyecreate Oct 05 '12 at 15:40
-
are you sure the opa smtp server receive the request? Add some log (like `jlog(from); jlog(raw_content);` to see. And searching for the error on google may help, it returns lot of results. – Cédrics Oct 07 '12 at 08:55
-
This is the full output from opa with jlog line: http://pastebin.com/SbDLsHiV None of it seems to point to a problem except the same error message. – eyecreate Oct 08 '12 at 14:07