Problem:
Before the company can send and receive mail through the POP3 protocol, so in SOAPUI with JavaMail can read the mail, later configured Office 365,POP3 protocol port is no longer open, mail all read failed, reported to login timeout, You need to use the EWS (Exchange Web Service) protocol instead.
Reference: http://blog.csdn.net/yangcheng33/article/details/55049629
This jar package needs to be imported: Ews-java-api-2.0.jar
Import Java.net.URIimport Java.net.URISyntaxExceptionimport Microsoft.exchange.webservices.data.core.*import Microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersionimport Microsoft.exchange.webservices.data.core.enumeration.property.*import Microsoft.exchange.webservices.data.core.enumeration.service.ConflictResolutionModeimport Microsoft.exchange.webservices.data.core.service.item.Itemimport Microsoft.exchange.webservices.data.core.service.schema.AppointmentSchemaimport Microsoft.exchange.webservices.data.credential.*import Microsoft.exchange.webservices.data.property.complex.MessageBodyimport Microsoft.exchange.webservices.data.search.*string Contentsubject = "Regarding area" String emailaddress = "[Email protected] "String password =" Autotest202010 "int maxemailsget = 5String queryString =" "Exchangeservice service = ge TService (emailaddress, password); finditemsresults<item> FindItems = Getemails (Maxemailsget, queryString, service);//Iterate message content for (Item Mail: FindItems) {String subject = Mail.getsubject ()//log.info "Email Subject:" +subjectmessagebody messagebody = Mail.getbod Y () Messagebody.setbodytype (bodytype.text) def hasattachment = mail.gethasattachments ()//log.info "has attatchment?:" +hasattachmentif (Subject.contains (Contentsubject) &&hasattachment.equals (true) &&mail.getIsRead ( ). Equals (False)) {Assert true, "check email pass"//email is read and synced to the mail server so that no matter how the message is viewed, the message is read state Mail.setisread (true) Mail.update (Conflictresolutionmode.alwaysoverwrite) Break}else if (maxemailsget==1) {assert false, "Check Email Fail"} maxemailsget--}//read inbox messages under public static finditemsresults<item> getemails (int maxemailsget, String queryString, Exchangeservice service) throws Exception {//default read messages under Inbox, max read 5 wellknownfoldername folderName = Wellknownfoldername.inbox;itemview Itemview = new Itemview (maxemailsget); finditemsresults<item> FindItems = Service.finditems (FolderName, queryString, Itemview);//define the underlying properties, this step must be, Otherwise it throws an exception PropertySet DEtailedpropertyset = new PropertySet (basepropertyset.firstclassproperties, appointmentschema.recurrence); Service.loadpropertiesforitems (FindItems, Detailedpropertyset); return findItems;} Connection server public static Exchangeservice GetService (string emailaddress, String password) throws URISyntaxException { Exchangeservice service = new Exchangeservice (EXCHANGEVERSION.EXCHANGE2010_SP1); Exchangecredentials credentials = new Webcredentials (emailaddress, password); Service.seturl (New URI ("https:// Outlook.office365.com/ews/exchange.asmx ")); Service.setcredentials (credentials); return service;}
Use the EWS (Exchange Web Service) protocol to read messages, send messages