in reply to Re^2: Using Net::SMTP to send email attachments
in thread Using Net::SMTP to send email attachments
As an update, I am finding that in different email clients, the text part of the email is also coming through as an attachment. So, from having no attachments I now have two attachments! It is probably a boundary problem, but I do not seem to be able to determine just where the problem is.
|
|---|
| Replies are listed 'Best First'. | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Re^4: Using Net::SMTP to send email attachments
by shmem (Chancellor) on May 01, 2017 at 13:29 UTC | ||||||||||||||||||||||||||||||||||
The second attachment is empty, right? Remove the last boundary. It is followed by nothing, and thus produces an empty attachment. update: Instead, output the boundary with "--" (two hyphens) attached, as per afoken's advice below.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
| [reply] | |||||||||||||||||||||||||||||||||
by afoken (Chancellor) on May 01, 2017 at 14:36 UTC | ||||||||||||||||||||||||||||||||||
The second attachment is empty, right? Remove the last boundary. It is followed by nothing, and thus produces an empty attachment. Wrong way. When avoiding perfectly working modules, one should at least read the relevant RFCs, in this case RFC 2046. It clearly states: The boundary delimiter line following the last body part is a distinguished delimiter that indicates that no further body parts will follow. Such a delimiter line is identical to the previous delimiter lines, with the addition of two more hyphens after the boundary parameter value. (Chapter 5.1.1. "Common Syntax", page 20) So, the code line must be changed from
to
Also, the boundary string should not appear anywhere else in the mail body. RFC 2046 states: NOTE: Because boundary delimiters must not appear in the body parts being encapsulated, a user agent must exercise care to choose a unique boundary parameter value. The boundary parameter value in the example above could have been the result of an algorithm designed to produce boundary delimiters with a very low probability of already existing in the data to be encapsulated without having to prescan the data. Alternate algorithms might result in more "readable" boundary delimiters for a recipient with an old user agent, but would require more attention to the possibility that the boundary delimiter might appear at the beginning of some line in the encapsulated part. The simplest boundary delimiter line possible is something like "---", with a closing boundary delimiter line of "-----". And RFC 2045 adds: Since the hyphen character ("-") may be represented as itself in the Quoted-Printable encoding, care must be taken, when encapsulating a quoted-printable encoded body inside one or more multipart entities, to ensure that the boundary delimiter does not appear anywhere in the encoded body. (A good strategy is to choose a boundary that includes a character sequence such as "=_" which can never appear in a quoted-printable body. See the definition of multipart messages in RFC 2046.) So, a "good" boundary string contains pseudo-random or hashed data and is not a single word. Some boundaries found in my inbox:
MIME::Lite constructs a boundary string like this:
(Ignore $VANILLA.) What you get is a fixed string, plus a few concatenated numbers (timestamp, process ID, and a simple counter). Overall, it should be quite unique, and it is unlikely to occur elsewhere in a message. No, this is not exciting, but it works. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] [select] | |||||||||||||||||||||||||||||||||
by shmem (Chancellor) on May 01, 2017 at 15:08 UTC | ||||||||||||||||||||||||||||||||||
Wrong way. When avoiding perfectly working modules, one should at least read the relevant RFCs, in this case RFC2046. It clearly states: Right. Sometimes memory betrays me; but it is not me who is "avoiding perfectly working modules"... So, a "good" boundary string contains pseudo-random or hashed data and is not a single word. Elsewhere in this thread: when assembling a multipart mail "avoiding perfectly working modules", if only for the sake of providing an example, I construct the boundary as '==' . encode_base64( join('',gettimeofday), '') which doesn't qualify as a single word also, and should be fairly unique, too.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
| [reply] [d/l] | |||||||||||||||||||||||||||||||||
by afoken (Chancellor) on May 06, 2017 at 16:35 UTC | ||||||||||||||||||||||||||||||||||
|
Re^4: Using Net::SMTP to send email attachments
by huck (Prior) on Apr 30, 2017 at 19:18 UTC | ||||||||||||||||||||||||||||||||||
It would be helpful to see what you did try You may have one too many $smtp->datasend("--$boundary\n"); in there. you dont want a boundary before the main text. The example seems to have one. | [reply] [d/l] | |||||||||||||||||||||||||||||||||
by astrobal (Acolyte) on May 01, 2017 at 06:00 UTC | ||||||||||||||||||||||||||||||||||
Here is the script I have been trying. I have tried commenting out various boundary lines, but without any improvement on the fact that the text part, "This is some text", is coming through as an attachment and the main body of the email is empty. The binary file attachment is coming through just fine though, so there is progress :-)</P Thanks again for looking
| [reply] [d/l] | |||||||||||||||||||||||||||||||||
by huck (Prior) on May 01, 2017 at 06:11 UTC | ||||||||||||||||||||||||||||||||||
Try changing this to this That matches what i see in my pop3 mailboxes better | [reply] [d/l] [select] | |||||||||||||||||||||||||||||||||
by astrobal (Acolyte) on May 01, 2017 at 12:55 UTC | ||||||||||||||||||||||||||||||||||