Search in sources :

Example 11 with Message

use of com.microsoft.graph.models.Message in project msgraph-beta-sdk-java by microsoftgraph.

the class OutlookTests method testSendDraft.

@Test
public void testSendDraft() {
    TestBase testBase = new TestBase();
    // Attempt to identify the sent message via randomly generated subject
    String draftSubject = "Draft Test Message " + Double.toString(Math.random() * 1000);
    Message newMessage = createDraftMessage(testBase, draftSubject);
    // Send the drafted message
    testBase.graphClient.me().mailFolders("Drafts").messages(newMessage.id).send().buildRequest().post();
    // Check that the sent message exists on the server
    MessageCollectionPage mcp = testBase.graphClient.me().messages().buildRequest().filter("subject eq '" + draftSubject + "'").get();
    assertFalse(mcp.getCurrentPage().isEmpty());
}
Also used : Message(com.microsoft.graph.models.Message) MessageCollectionPage(com.microsoft.graph.requests.MessageCollectionPage) Test(org.junit.jupiter.api.Test)

Example 12 with Message

use of com.microsoft.graph.models.Message in project msgraph-beta-sdk-java by microsoftgraph.

the class OutlookTests method testSendMail.

@Test
public void testSendMail() {
    TestBase testBase = new TestBase();
    User me = testBase.graphClient.me().buildRequest().get();
    Recipient r = new Recipient();
    EmailAddress address = new EmailAddress();
    address.address = me.mail;
    r.emailAddress = address;
    Message message = new Message();
    message.subject = "Test E-Mail";
    message.from = r;
    ArrayList<Recipient> recipients = new ArrayList<Recipient>();
    recipients.add(r);
    message.toRecipients = recipients;
    testBase.graphClient.me().sendMail(UserSendMailParameterSet.newBuilder().withMessage(message).withSaveToSentItems(true).build()).buildRequest().post();
}
Also used : User(com.microsoft.graph.models.User) Message(com.microsoft.graph.models.Message) ArrayList(java.util.ArrayList) Recipient(com.microsoft.graph.models.Recipient) EmailAddress(com.microsoft.graph.models.EmailAddress) Test(org.junit.jupiter.api.Test)

Example 13 with Message

use of com.microsoft.graph.models.Message in project msgraph-beta-sdk-java by microsoftgraph.

the class OutlookTests method sendEmailWithAttachment.

@Test
public void sendEmailWithAttachment() throws Exception {
    TestBase testBase = new TestBase();
    Message message = getMessage();
    message.hasAttachments = true;
    AttachmentCollectionResponse response = new AttachmentCollectionResponse();
    response.value = Arrays.asList(getFileAttachment(), getItemAttachmentWithEvent(), getItemAttachmentWithContact());
    message.attachments = new AttachmentCollectionPage(response, null);
    testBase.graphClient.me().sendMail(UserSendMailParameterSet.newBuilder().withMessage(message).withSaveToSentItems(true).build()).buildRequest().post();
}
Also used : AttachmentCollectionPage(com.microsoft.graph.requests.AttachmentCollectionPage) Message(com.microsoft.graph.models.Message) AttachmentCollectionResponse(com.microsoft.graph.requests.AttachmentCollectionResponse) Test(org.junit.jupiter.api.Test)

Example 14 with Message

use of com.microsoft.graph.models.Message in project msgraph-beta-sdk-java by microsoftgraph.

the class OutlookTests method uploadEmailAsDraftWithAttachmentThenSend.

@Test
public void uploadEmailAsDraftWithAttachmentThenSend() {
    TestBase testBase = new TestBase();
    Message message = getMessage();
    Message m = testBase.graphClient.me().messages().buildRequest().post(message);
    assertNotNull(m);
    testBase.graphClient.me().messages(m.id).send().buildRequest().post();
}
Also used : Message(com.microsoft.graph.models.Message) Test(org.junit.jupiter.api.Test)

Example 15 with Message

use of com.microsoft.graph.models.Message in project team-catalog by navikt.

the class MailMessage method compose.

public static Message compose(String to, String subject, String messageBody) {
    Message message = new Message();
    message.toRecipients = List.of(recipient(to));
    message.subject = subject;
    message.body = new ItemBody();
    message.body.contentType = BodyType.HTML;
    message.body.content = messageBody;
    return message;
}
Also used : Message(com.microsoft.graph.models.Message) ItemBody(com.microsoft.graph.models.ItemBody)

Aggregations

Message (com.microsoft.graph.models.Message)15 Test (org.junit.jupiter.api.Test)10 EmailAddress (com.microsoft.graph.models.EmailAddress)6 Recipient (com.microsoft.graph.models.Recipient)6 ArrayList (java.util.ArrayList)6 User (com.microsoft.graph.models.User)4 AttachmentItem (com.microsoft.graph.models.AttachmentItem)2 UploadSession (com.microsoft.graph.models.UploadSession)2 AttachmentCollectionPage (com.microsoft.graph.requests.AttachmentCollectionPage)2 AttachmentCollectionResponse (com.microsoft.graph.requests.AttachmentCollectionResponse)2 MessageCollectionPage (com.microsoft.graph.requests.MessageCollectionPage)2 LargeFileUploadTask (com.microsoft.graph.tasks.LargeFileUploadTask)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ItemBody (com.microsoft.graph.models.ItemBody)1