I've got a script that basically access email through IMAP and then finds all the .wav audio and download them into a folder locally on the server.
I'm struggling to get it to access Office 365 through IMAP.
Keeps saying Couldn't open stream {outlook.office365.com:993/imap/ssl/novalidate-cert}Inbox.
&
Cannot connect to {outlook.office365.com:993/imap/ssl/novalidate-cert}INBOX: Too many login failures
See whole script below;
<?php
$MSG_DIR = "D:/Voicemail/Messages/";
$USER = "xx";
$PASS = "xx";
// connect to JARVIS
echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;font-weight: bold;color:#2471b6'>Connecting to J.A.R.V.I.S.</div>\n<br/>";
$host = "{outlook.office365.com:993/imap/ssl/novalidate-cert}Inbox";
$mbox=imap_open($host,$USER,$PASS, NULL, 1, array('DISABLE_AUTHENTICATOR' => 'GSSAPI')) or die("Can't connect: " . imap_last_error());
// Look over mailbox
echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;font-weight: bold;color:#2471b6'>Connection Complete...</div>\n<br/>";
$MC = imap_check($mbox) or die("Can't check for messages");
$overview = imap_fetch_overview( $mbox, "1:".$MC->Nmsgs, 0 ) or die( "Can't get headers");
$countThis = 0;
foreach ( $overview as $email )
{
$subject = $email->subject;
$udate = $email->udate;
if( preg_match('/Voice Message from ([0-9]+)/', $subject, $groups) ||
preg_match('/Voice Message from ([a-zA-Z]\w+)/', $subject, $groups) )
{
$filename = $MSG_DIR."/".$groups[1].date(" d-m H-i-s", $udate).".wav";
if( file_exists( $filename ) )
{
echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;color:#000000'>Skipping $filename...</div>\n";
}
else
{
echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;color:#000000'>Extracting $filename...</div>\n";
$structure = imap_fetchstructure($mbox,$email->uid, FT_UID) or die( "could not fetch structure");
foreach ( $structure->parts as $part )
{
if( $part->subtype == "X-WAV" || $part->subtype=="WAV" || $part->subtype=="OCTET-STREAM")
{
// found it!
$body = imap_base64( imap_fetchbody( $mbox, $email->uid, 2, FT_UID ) ) or die( "Could not fetch part");
file_put_contents( $filename, $body );
}
else
{
}
}
}
$countThis++;
}
}
echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;font-weight: bold;color:#2471b6'></br>Found $countThis Voicemails\r\n</div>";
echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;font-weight: bold;color:#ff0000'></br>Disconnecting from J.A.R.V.I.S.\r\n</div>";
imap_close($mbox);
?>
This was previously used on Exchange 2010.
Hope someone can help.
Thank you!