Page 1 of 1

cache complete email - attachments and all

Posted: Tue Feb 05, 2008 9:34 pm
by alex.barylski
I asked a similar quesiton the other day...you told me ot use $message->build()->readFull().

Problem is...because I'm not actually sending the email at this point, I don't need the connection classes...something like this:

Code: Select all

$message = new Swift_Message($subject, $content);
$message->setReturnPath('bounce@domain.com');
$message->setContentType('text/html');
 
$address = new Swift_Address(
 'myemail@domain.com',
 'My Company Name'
);
If I check the $message->build->readFull() how does the Swift_Address get associated with the overall email?

Basically I need to cache the entire email in it's most completed form without sending...is it possible to compile/build a complete email with psuedo-headers an all??? Does Swift send headers directly using header() when it's prepared an email? Anyway to capture the email using output buffering perhaps - and just disable the actual sending???

Re: cache complete email - attachments and all

Posted: Tue Feb 05, 2008 10:03 pm
by Kieran Huggins
I have a feeling that serializing the completed message object could work, but I'm not 100% sure.

In reference to the headers, don't forget that these are email headers, not http headers. They're not sent anywhere until the whole message is sent, they just appear at the top of the email data, separated by an empty line.

Re: cache complete email - attachments and all

Posted: Tue Feb 05, 2008 11:37 pm
by alex.barylski
I thought about dumping the Swift object, but the send() accepts the Address object and to address and I couldn't find any setters for those in the message API - maybe i'm just blind. :P

Re: cache complete email - attachments and all

Posted: Tue Feb 05, 2008 11:43 pm
by Kieran Huggins
You might have to dump the recipients array along side the message object.

Mind you, what I do is just add the message details and recipient list to some DB tables, then build the message as I send it. That might be a better approach in the end...

viewtopic.php?f=52&t=76722&p=439267#p439267

Re: cache complete email - attachments and all

Posted: Wed Feb 06, 2008 12:27 am
by alex.barylski
I need the entire email as a whole...so I can't use that approach - as it stands the recipient(s) are added dynamically. Basically I need the complete email with everything hardcoded - essentially what Swift sends out I assume???

Not sure if you actually the the TO: fields along with the command to SMTP or not...I would think from looking at emails in my inbox, under the hood they appear to have all those details hardcoded into the email itself. That is basically what I need.

Re: cache complete email - attachments and all

Posted: Wed Feb 06, 2008 12:31 am
by Chris Corbyn
Use setTo(), setBcc() etc in Swift_Message then build the message. Swift does this internally usually but you can do it yourself if you want.

Re: cache complete email - attachments and all

Posted: Wed Feb 06, 2008 1:36 am
by alex.barylski
I looked into setTo() but it appears to accept only a string, whereas the Swift_Address object accepts both a name and an email???

Are the two just combined into a single string somewhere in Swift? I guess I should have looked into Swift_Address to see if if there was a build() method as well as just use that to construct the string...?

Cheers :)

Re: cache complete email - attachments and all

Posted: Wed Feb 06, 2008 2:03 am
by Chris Corbyn
setTo() accepts a Swift_Address object too. So do all the other address headers.