public EmailMessage(String from, String subject, String body) { setFrom(from); setSubject(subject); setBody(body); }
EmailMessage emailMessage; while (resultSet.next()) { emailMessage = new EmailMessage(); emailMessage.setCategory(resultSet.getString("category")); emailMessage.setSubject(resultSet.getString("subject")); emailMessage.setBody(resultSet.getString("body")); emailMessageList.add(emailMessage); }
for (Message incomingMessage : messageInitRequest.getMessageList()) { if (incomingMessage instanceof EmailMessage) { EmailMessage emailMessage = (EmailMessage) incomingMessage; System.out.println("Type: Email"); System.out.println(emailMessage.getMessageBody()); System.out.println(emailMessage.getSubject()); } else if (incomingMessage instanceof SMSMessage) { SMSMessage smsMessage = (SMSMessage) incomingMessage; System.out.println("Type: SMS"); System.out.println(smsMessage.getMessageBody()); } }
public void sendEmail() { EmailMessage email = new EmailMessage(); email.addTo(EmailObject.mail); }
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); ExchangeCredentials credentials = new WebCredentials("user", "pw"); service.setCredentials(credentials); service.setUrl(new URI("https:// s e r v e r /ews/exchange.asmx")); EmailAddress mEmail = new EmailAddress("your email / test email"); EmailMessage message = new EmailMessage(service); message.getToRecipients().add(mEmail); message.setFrom(mEmail); message.setSubject("Hello world!"); message.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Android API.")); message.send();
EmailMessage message = new EmailMessage(); message.setHeaders(email.getHeader()); message.setBody(email.getMessage()); message.setHeader("multipart-subtype", "alternative"); message.setSubject(email.getSubject()); message.setFrom(email.getFromAddress()); message.setContentType("text/html; charset=UTF-8"); message.addAttachment(a); message.addRecipient(EmailAddress.RecipientType.TO, recipient.getDisplayName(), emailAddress); } else { logger.debug("Invalid email for user: " + recipient.getDisplayId() + ". No email will be sent to this user");
from = new InternetAddress(msg.getFrom().getAddress(), true); from.setPersonal(msg.getFrom().getPersonal()); + msg.getFrom().getAddress(), msg.getFrom()); + msg.getFrom().getAddress(), msg.getFrom()); InternetAddress[] replyTo = emails2Internets(msg.getReplyTo(), invalids); if (!invalids.isEmpty()) InternetAddress[] to = emails2Internets(msg.getRecipients(RecipientType.TO), invalids); InternetAddress[] cc = emails2Internets(msg.getRecipients(RecipientType.CC), invalids); InternetAddress[] bcc = emails2Internets(msg.getRecipients(RecipientType.BCC), invalids); InternetAddress[] actual = emails2Internets(msg.getRecipients(RecipientType.ACTUAL), invalids); List<String> headers = msg.extractHeaders(); String contentType = EmailHeaders.CONTENT_TYPE + ": " + msg.getContentType(); if (msg.getCharacterSet() != null && msg.getCharacterSet().trim().length() != 0) contentType += "; charset=" + msg.getCharacterSet(); if (ContentType.TEXT_PLAIN.equals(msg.getCharacterSet()) && msg.getFormat() != null && msg.getFormat().trim().length() != 0)
service.setUrl(new URI("Mail server URL")); msg = new EmailMessage(service); msg.setSubject(subject); msg.setBody(MessageBody.getMessageBodyFromText(bodyContent)); msg.getAttachments().addFileAttachment("Complete File Path"); if(to == null || to.equals("")){ LOGGER.warn("To distribution list is empty. Could not send the mail "); for(String mailTo : mailTos){ if(mailTo != null && !mailTo.isEmpty()) msg.getToRecipients().add(mailTo); for(String mailCc : mailCCs){ if(mailCc != null && !mailCc.equals("")) msg.getCcRecipients().add(mailCc); msg.send(); LOGGER.debug("Mail successfully send "); return true;
public static void sendMail(String[] addresses) throws Exception { // enter vaild mail id and password ExchangeCredentials credentials = new WebCredentials("mail_id", "passwd"); service.setCredentials(credentials); // enter vaild server url service.setUrl(new URI("server")); EmailMessage mail = new EmailMessage(service); mail.setSubject("Hello EWS Send"); mail.setBody(new MessageBody("pffed bye!!!")); for (String string : addresses) mail.getToRecipients().add(new EmailAddress(string)); mail.sendAndSaveCopy(); }
/** * Add a header to this message. If the key is found in the headers of this message, the value * is appended to the previous value found and separated by a space. A key of null will not be * added. If value is null, previous entries of the matching key will be removed. * * @param key * The key of the header. * @param value * The value of the header. */ public void addHeader(String key, String value) { if (headers == null || headers.get(key) == null) { setHeader(key, value); } else if (key != null && value != null) { String prevVal = headers.get(key); prevVal += " " + value; headers.put(key, prevVal); } else if (value == null) { removeHeader(key); } }
EmailMessage msg = new EmailMessage(...); // initialization Date date = msg.getDate(); date.setTime(...); //ooops, our msg object has another date now
public void testSend() throws Exception { // you need to suppress the constructor before you mock the class. PowerMockito.suppress(PowerMockito.constructor(EmailMessage.class)); EmailMessage emailMessage = PowerMockito.mock(EmailMessage.class); Email email = new Email(); emailMessage.setSubject(email.getSubject()); // ...your other code here ... }
/** * Add an attachment to this message. Same as addAttachment(new Attachment(file)). * * @param file */ public void addAttachment(File file) { addAttachment(new Attachment(file, file.getPath())); }
/** * Sets headers on this message. The expected format of each header is key: value. * * @param headers */ public void setHeaders(List<String> headers) { if (headers != null) { for (String header : headers) { int splitPoint = header.indexOf(":"); String key = header.substring(0, splitPoint); String value = null; if (splitPoint != header.length() - 1) { value = header.substring(splitPoint + 1).trim(); } setHeader(key, value); } } }
new EmailMessage() .from("demo@guilhermechapiewski.com") .to("destination@address.com") .withSubject("Fluent Mail API") .withBody("Demo message") .send();
// get messages in mailbox Enumeration e = imap.getNewMessages(); // loop thru all messages in mailbox while(e.hasMoreElements()) { EmailMessage message = (EmailMessage)e.nextElement(); // print out subject, or do what you want System.out.println(message.getSubject());
private HashMap<String,String> downloadInLineImage(Item item, String dynamicOutputDirectory) throws Exception, ServiceLocalException { //create output directory if not present //bind the item to a new email message. if you do not bind, then the getHasAttachments() function will fail EmailMessage mostRecentMatch = (EmailMessage)item; String from = mostRecentMatch.getFrom().getAddress(); String user =StringUtils.substringBefore(from, "@"); AttachmentCollection collection=item.getAttachments(); HashMap<String,String> inlineFiles=new HashMap<String,String>(); if(collection.getCount()>0) { for (Attachment attachment : collection.getItems()) { if(attachment.getIsInline()) { FileAttachment currentFile = (FileAttachment) attachment; String filePath=dynamicOutputDirectory+"/"+user+currentFile.getName(); File file=new File(filePath); FileOutputStream fio=new FileOutputStream(file); currentFile.load(fio); inlineFiles.put(currentFile.getContentId(), filePath); fio.close(); } } }
public void sendEmail(String body, String subject, String recipients, String from) { service = new ExchangeService(); ExchangeCredentials credentials = new WebCredentials(username, password); service.setCredentials(credentials); service.setUrl(ewsUri); try { EmailMessage replymessage = new EmailMessage(service); EmailAddress fromEmailAddress = new EmailAddress(from); replymessage.setFrom(fromEmailAddress); replymessage.getToRecipients().add(recipients); //replymessage.setInReplyTo(recipients); replymessage.setSubject(subject); replymessage.setBody(new MessageBody(body)); replymessage.send(); }catch (Exception e) { logger.error(""+e); } }
/** * Add a header to this message. If the key is found in the headers of this message, the value * is appended to the previous value found and separated by a space. A key of null will not be * added. If value is null, previous entries of the matching key will be removed. * * @param key * The key of the header. * @param value * The value of the header. */ public void addHeader(String key, String value) { if (headers == null || headers.get(key) == null) { setHeader(key, value); } else if (key != null && value != null) { String prevVal = headers.get(key); prevVal += " " + value; headers.put(key, prevVal); } else if (value == null) { removeHeader(key); } }
/** * Add an attachment to this message. Same as addAttachment(new Attachment(file)). * * @param file */ public void addAttachment(File file) { addAttachment(new Attachment(file, file.getPath())); }