Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mixed + alternative not supported #25

Open
freste opened this issue May 15, 2015 · 8 comments
Open

mixed + alternative not supported #25

freste opened this issue May 15, 2015 · 8 comments

Comments

@freste
Copy link

freste commented May 15, 2015

docs should indicate that you can't use both text_body, html_body, with attach. Maybe in TODO or attach/attach_file sections?

E.g.:

    Email::Stuffer->from       ('[email protected]'             )
                    ->to       ('[email protected]'     )
                    ->text_body('plain text'              )
                    ->html_body('html text'               )
                    ->attach_file('dead_bunbun_faked.gif' )
    ->as_string;

Produces multipart/mixed header with 3 parts; but no multipart/alternative
Should be two parts, multipart/alternative and the attachment, both inside a multipart/mixed

@rjbs
Copy link
Owner

rjbs commented May 23, 2015

Gotta be a bug. I need to make a run through the bugs on E-S and will check it out when I get there.

@StarLightPL
Copy link

Any progress on patching this?

@biggle1856
Copy link

Workaround:

my $mail=Email::Stuffer->new({ transport=>$transport})
	->to($to) 
	->from($from) 
	->subject($subject)
	->text_body($plain_text)
	->html_body($html_text);

if($attachment){
	$mail->{parts}->[0]=Email::MIME->create(
		attributes=>{content_type=>q(multipart/alternative)},
		parts=>[delete $mail->{parts}->[0,1]]
	);
	$mail->attach_file($attachment, filename=>$filename, disposition=>'attachment');
}

@StarLightPL
Copy link

Thx biggle1856, I will test that out at work 👍

@simongreen-net
Copy link

I've written a patch to fix this issue. I will test it over the next couple of days, and then submit a PR. Issue #33 should probably be closed, as it is a duplicate of this one.

@simongreen-net
Copy link

PR 40 submitted :)

simongreen-net added a commit to simongreen-net/Email-Stuffer that referenced this issue Jun 25, 2017
simongreen-net added a commit to simongreen-net/Email-Stuffer that referenced this issue Jun 25, 2017
@ssimms
Copy link

ssimms commented May 4, 2018

Here's a modified workaround, based on the one above by biggles1856 (thanks!). When I tried that one, the text body got lost. Not sure why, but it's possibly related to the following note in perldoc -f delete:

WARNING: Calling "delete" on array values is strongly discouraged.
The notion of deleting or checking the existence of Perl array
elements is not conceptually coherent, and can lead to surprising
behavior.

This version seems to work:

my $mail = Email::Stuffer->new({ transport => $transport })
	->to($to)
	->from($from)
	->subject($subject)
	->text_body($plain_text)
	->html_body($html_text);

if ($attachment) {
	$mail->{parts} = [ Email::MIME->create(
		attributes => {content_type => q(multipart/alternative)},
		parts => $mail->{parts}
	) ];
	$mail->attach_file($attachment, filename => $filename, disposition => 'attachment');
}

@trmz
Copy link

trmz commented Apr 11, 2024

For those curious, biggle1856's solution should work ... if you change ->[0,1] to ->@[0,1].
May be what was intended originally.

That ->@ syntax is called postfix dereferencing, I think.
Note that it "became stable in Perl v5.24", so may not be available to you, if running on older systems.

Kind of funny (and unfortunate), with use warnings Perl will tend to complain about "Useless use of a constant (n) in void context" ... except for indices 0 or 1, as was the case here. 😄

Anyway, would be nice to have this functionality provided by default, whether merging PR #41 as-is or updated, or offering any other interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants