parsing - parse attachment from multipart mail content string in java -
i'm testing application sending mail attachment in integration environment. i'm setting fake smtp mail server (http://quintanasoft.com/dumbster/) , configure application use it. @ end of test want check if application has sent email via fake mail server , want know, if content (at least attached file) i'm expecting.
dumpster wrapping these mails own objects containing header key-value pairs , body plain text. question how can part mail body , evaluate attached file content it.
attach file of mime-types in javamail. sending email on smtp allows make use of fact there string of data inside body of email before bytes of file. bytes of file base64 , included in main chunk of characters of email.
private static final string your_attacmetn_data = "content-type: image/jpeg; name=invoice.jpgcontent-transfer-encoding: base64content-disposition: attachment; filename=image.jpg"; @before public final void setup() throws userexception{ server = simplesmtpserver.start(); } @after public final void teardown(){ server.stop(); } @test public void test_that_attachment_has_been_recieved() throws ioexception, messagingexception { email = getmessage(); youremailsendingclass.sendemail(email); iterator<smtpmessage> = server.getreceivedemail(); smtpmessage recievedmessage = (smtpmessage)it.next(); asserttrue(recievedmessage.getbody.contains(your_attachment_data))); }
here page of did similar in greater detail. http://www.lordofthejars.com/2012/04/why-does-rain-fall-from-above-why-do.html
Comments
Post a Comment