java - SubethaSmtp working example -
can please tell me how use subethasmtp library? want retrieve mails gmail inbox , display them or 1 of them in console window.
i studied of api doc i'm not being able put pieces things working.
can please tell me working example?
i wrote code build grails application. may find bad code habits it's okey sample application.
here code in src/groovy folder :
class messagehandlerfactoryimpl implements messagehandlerfactory { @override messagehandler create(messagecontext ctx) { return new messagehandlerimpl(ctx) } }
class messagehandlerimpl implements messagehandler { messagecontext context messagehandlerimpl(messagecontext context) { this.context = context } @override void from(string from) { println "from: ${from}" } @override void recipient(string recipient) { println "recipient: ${recipient}" } @override void data(inputstream data) { println "data" println "-------------------" bufferedreader reader = new bufferedreader(new inputstreamreader(data)) stringbuilder builder = new stringbuilder() string line while ((line = reader.readline()) != null) { builder.append(line + "\n") } println builder.tostring() } @override void done() { println "done" } }
class simplemessagelistenerimpl implements simplemessagelistener { @override boolean accept(string from, string recipient) { println "accept: ${from} \n>> ${recipient}" return false } @override void deliver(string from, string recipient, inputstream data) { try { println "deliver: ${from} \n>> ${recipient} \n>>> ${data.read()}" } catch (toomuchdataexception e) { println "toomuchdataexception: ${e.message}" } catch (ioexception e) { println "ioexception: ${e.message}" } } }
class usernamepasswordvalidatorimpl implements usernamepasswordvalidator { @override void login(string username, string password) { try { println "login:::::::" } catch(loginfailedexception e) { println "loginfailedexception: ${e.message}" } } }
and here controller code.
class subethacontroller { smtpserver server def index() { messagehandlerfactoryimpl factory = new messagehandlerfactoryimpl() server = new smtpserver(factory) server.hostname = "imap.gmail.com" server.port = 993 server.authenticationhandlerfactory = new easyauthenticationhandlerfactory(new usernamepasswordvalidatorimpl()) server.start() } def stop() { server?.stop() } wiser wiser def wiser() { server = new smtpserver(new simplemessagelisteneradapter(new simplemessagelistenerimpl())) server.start() wiser = new wiser() wiser.setport(25001) wiser.start() (wisermessage message : wiser.getmessages()) { string esender = message.getenvelopesender() string ereceiver = message.getenvelopereceiver() println ">>>>>>>message.getmimemessage ${message.getmimemessage()}" } } def wisers() { wiser?.stop() } }
thanks.
okey... found answer... code written , working fine. didn't know how send messages listening smtp server on port. used telnet program , sent emails smtp server running on localhost. create dns mapping make work on internet.
thanks nicolás showing interest.
Java - Subethasmtp Working Example - >>>>> Download Now
ReplyDelete>>>>> Download Full
Java - Subethasmtp Working Example - >>>>> Download LINK
>>>>> Download Now
Java - Subethasmtp Working Example - >>>>> Download Full
>>>>> Download LINK RB