afterlogic / webmail-lite

AfterLogic WebMail Lite PHP. Fast and easy-to-use webmail front-end for your existing IMAP mail server, Plesk or cPanel.
https://afterlogic.org/webmail-lite
GNU Affero General Public License v3.0
443 stars 120 forks source link

How can i add an attachment using the php API #82

Closed alfonsobries closed 6 years ago

alfonsobries commented 6 years ago

Im tryiing to send an email with the php api according to this example: https://afterlogic.com/docs/webmail-pro/integration-and-development/sending-mail

Works fine for simple email but also i want to add attachments, i read the entirely documentation, and explore the source code but didnt find a function for add attachment to the message

Can you please help me?

alfonsobries commented 6 years ago

I think i closest to the solution, i found the Attachments() function in the Message class, it attach the files to the mail but currently sends empty files, (i made a few combinations but i cant achieve the attachment works)

any idea?

 $oAttachment = \MailSo\Mime\Attachment::NewInstance(
    $rResource = file_get_contents($full_path), // full path is the path of the file uploaded to the server
    $sFileName = $attachment_name, // This is the file name, example: "my_file.pdf"
    $iFileSize = filesize($full_path),
);

$oMessage->Attachments()->Add($oAttachment);
alfonsobries commented 6 years ago

I think i achieved to solve the problem, instead using file_get_contents i use fopen to create a resource and it works great!

$oAttachment = \MailSo\Mime\Attachment::NewInstance(
    fopen($full_path, 'r'),
    $sFileName = $attachment_name,
    $iFileSize = filesize($full_path)
);

$oMessage->Attachments()->Add($oAttachment);