0
votes

I have a hard time to send multipart MIME message via SMTP using PHP library called MailSo. Provided two examples are limited. No word on how to create headers, message body, multipart MIME message itself and then send it.

Current webmail (Rainloop) is running on MailSo and I want to avoid using 3rd party library on top of MailSo. Going forward all email actions are stored in the Rainloop Actions.php file.

Based on that to create multipart MIME message I should to create $oMessage object (\MailSo\Mime\Message) and I'm able partially do that like to add subject, message ID, custom headers, message body text but going further I'm not able to set MIME boundaries (to store original message body as a boundary as well additional content type as text/plain) not talking about sending $oMessage object via SMTP.

Here is my test code so far:

include 'lib/MailSo/MailSo.php';

echo '<pre>';
$oLogger = \MailSo\Log\Logger::SingletonInstance()
    ->Add(\MailSo\Log\Drivers\Inline::NewInstance("\r\n", true))
;

$sToEmails = 'Me As Tester <[email protected]>';
$oToEmails = \MailSo\Mime\EmailCollection::NewInstance($sToEmails);

$sFromEmails = 'Baba Ganush <[email protected]>';
$oFromEmails = \MailSo\Mime\Email::NewInstance($sFromEmails);

$oMessage = \MailSo\Mime\Message::NewInstance();
$oMessage->RegenerateMessageId();

$oMessage->SetXMailer('RainLoop/1.0.0');

$oMessage->SetCustomHeader('test-header','test-header-value');

$oMessage->setSubject("Test message");
$oMessage->AddText('Generated message body goes here...');

$oMessage->SetFrom($oFromEmails);
$oMessage->SetTo($oToEmails);

$oLogger->WriteDump($oMessage);
1
Why not use something much more known like PHPMailer?Patrick Q
@PatrickQ I have PHPMailer or Swift Mailer as a final choice but current webmail (Rainloop) is running on MailSoJackTheKnife
we are not the support for every third party appuser8011997
How are you sending regular messages using this library? Can you post the code you have that is working and the code that you've tried that isn't?Patrick Q
@PatrickQ I have updated OP. I may update more when I will proceed with a discovery on Rainloop part how MailSo works.JackTheKnife

1 Answers

-1
votes

Well, I have figured out how to send an email message created using MailSo library (w/o any attachments for now)

Example code below

        if($oMessage){
            $rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
            $iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter($oMessage->ToStream(true), array($rMessageStream), 8192, true, true, true);
        }

        $aToCollection = $oMessage->GetTo();
        if ($aToCollection && $oFrom)
        {
            $sRawBody = @stream_get_contents($rMessageStream);

            if (!empty($sRawBody))
            {
                $sMailTo = trim($aToCollection->ToString(true));
                $sMailSubject = trim($oMessage->GetSubject());
                $sMailSubject = 0 === strlen($sMailSubject) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(\MailSo\Base\Enumerations\Encoding::BASE64_SHORT, $sMailSubject);
                $sMailHeaders = $sMailBody = '';
                list($sMailHeaders, $sMailBody) = explode("\r\n\r\n", $sRawBody, 2);
                unset($sRawBody);
                $sMailHeaders = \MailSo\Base\Utils::RemoveHeaderFromHeaders($sMailHeaders, array(\MailSo\Mime\Enumerations\Header::TO_,\MailSo\Mime\Enumerations\Header::SUBJECT));
                mail($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders);
            }
        }