use of com.google.api.services.gmail.model.Message in project camel by apache.
the class GmailUsersMessagesIntegrationTest method createTestEmail.
private Message createTestEmail() throws MessagingException, IOException {
com.google.api.services.gmail.model.Profile profile = requestBody("google-mail://users/getProfile?inBody=userId", CURRENT_USERID);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage mm = new MimeMessage(session);
mm.addRecipients(javax.mail.Message.RecipientType.TO, profile.getEmailAddress());
mm.setSubject("Hello from camel-google-mail");
mm.setContent("Camel rocks!", "text/plain");
Message createMessageWithEmail = createMessageWithEmail(mm);
return createMessageWithEmail;
}
use of com.google.api.services.gmail.model.Message in project camel by apache.
the class GmailUsersMessagesIntegrationTest method testMessages.
@Test
public void testMessages() throws Exception {
// ==== Send test email ====
Message testEmail = createTestEmail();
Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is com.google.api.services.gmail.model.Message
headers.put("CamelGoogleMail.content", testEmail);
com.google.api.services.gmail.model.Message result = requestBodyAndHeaders("direct://SEND", null, headers);
assertNotNull("send result", result);
String testEmailId = result.getId();
// ==== Search for message we just sent ====
headers = new HashMap<String, Object>();
headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
// using String message body for single parameter "userId"
ListMessagesResponse listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
assertTrue(idInList(testEmailId, listOfMessages));
// ===== trash it ====
headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", testEmailId);
requestBodyAndHeaders("direct://TRASH", null, headers);
// ==== Search for message we just trashed ====
headers = new HashMap<String, Object>();
headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
// using String message body for single parameter "userId"
listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
assertFalse(idInList(testEmailId, listOfMessages));
// ===== untrash it ====
headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", testEmailId);
requestBodyAndHeaders("direct://UNTRASH", null, headers);
// ==== Search for message we just trashed ====
headers = new HashMap<String, Object>();
headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
// using String message body for single parameter "userId"
listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
assertTrue(idInList(testEmailId, listOfMessages));
// ===== permanently delete it ====
headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelGoogleMail.userId", CURRENT_USERID);
// parameter type is String
headers.put("CamelGoogleMail.id", testEmailId);
requestBodyAndHeaders("direct://DELETE", null, headers);
// ==== Search for message we just deleted ====
headers = new HashMap<String, Object>();
headers.put("CamelGoogleMail.q", "subject:\"Hello from camel-google-mail\"");
// using String message body for single parameter "userId"
listOfMessages = requestBody("direct://LIST", CURRENT_USERID);
assertFalse(idInList(testEmailId, listOfMessages));
}
use of com.google.api.services.gmail.model.Message in project camel by apache.
the class GmailUsersMessagesIntegrationTest method createMessageWithEmail.
private Message createMessageWithEmail(MimeMessage email) throws MessagingException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
email.writeTo(baos);
String encodedEmail = Base64.encodeBase64URLSafeString(baos.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
use of com.google.api.services.gmail.model.Message in project camel by apache.
the class GmailUsersThreadsIntegrationTest method createMessageWithEmail.
private Message createMessageWithEmail(MimeMessage email) throws MessagingException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
email.writeTo(baos);
String encodedEmail = Base64.encodeBase64URLSafeString(baos.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
use of com.google.api.services.gmail.model.Message in project data-transfer-project by google.
the class GoogleMailService method importItem.
@Override
public void importItem(MailModelWrapper model) throws IOException {
log("importItem, model: %s", model);
for (MailMessageModel message : model.getMessages()) {
// TODO: Avoid re-looking up lable on each fetch
String labelId = getMigratedLabelId();
Message newMessage = new Message().setRaw(message.getRawString()).setLabelIds(ImmutableList.of(labelId));
gmail.users().messages().insert(USER, newMessage).execute();
}
}
Aggregations