44import com .microsoft .graph .models .extensions .Message ;
55import com .microsoft .graph .models .extensions .Recipient ;
66import com .microsoft .graph .models .extensions .User ;
7+ import com .microsoft .graph .options .QueryOption ;
8+ import com .microsoft .graph .requests .extensions .IMessageCollectionPage ;
79import com .microsoft .graph .requests .extensions .IUserCollectionPage ;
810
911import org .junit .Test ;
1820
1921import javax .xml .datatype .DatatypeFactory ;
2022import javax .xml .datatype .Duration ;
21- import java .lang .reflect .Array ;
2223
2324import java .util .ArrayList ;
2425
@@ -72,4 +73,36 @@ public void testGetFindMeetingTimes() {
7273 }
7374
7475 }
76+
77+ @ Test
78+ public void testSendDraft () {
79+ TestBase testBase = new TestBase ();
80+
81+ //Attempt to identify the sent message via randomly generated subject
82+ String draftSubject = "Draft Test Message " + Double .toString (Math .random ()*1000 );
83+
84+ User me = testBase .graphClient .me ().buildRequest ().get ();
85+ Recipient r = new Recipient ();
86+ EmailAddress address = new EmailAddress ();
87+ address .address = me .mail ;
88+ r .emailAddress = address ;
89+ Message message = new Message ();
90+ message .subject = draftSubject ;
91+ ArrayList <Recipient > recipients = new ArrayList <Recipient >();
92+ recipients .add (r );
93+ message .toRecipients = recipients ;
94+ message .isDraft = true ;
95+
96+ //Save the message as a draft
97+ Message newMessage = testBase .graphClient .me ().messages ().buildRequest ().post (message );
98+ //Send the drafted message
99+ testBase .graphClient .me ().mailFolders ("Drafts" ).messages (newMessage .id ).send ().buildRequest ().post ();
100+
101+ java .util .List <QueryOption > options = new ArrayList <QueryOption >();
102+ QueryOption o = new QueryOption ("$filter" , "subject eq '" + draftSubject + "'" );
103+ options .add (o );
104+ //Check that the sent message exists on the server
105+ IMessageCollectionPage mcp = testBase .graphClient .me ().messages ().buildRequest (options ).get ();
106+ assertFalse (mcp .getCurrentPage ().isEmpty ());
107+ }
75108}
0 commit comments