Search code examples
cocoaemailmimeemail-attachments

Boundary in attachment


I wrote a simple mailer, but every time I send an attachment I have my boundary within the attachment. The following goes to the server:

From: Some valid E-Mail
Reply-To: The same valid E-Mail
To: my E-Mail (hosted by 1&1)
Cc: 
Bcc: 
Subject: Anhang Serie
MIME-Version: 1.0
X-Mailer: KizzyCode Mailer 0.1
X-Priority: 1
Content-Type: multipart/mixed;
     boundary="--KCMailC68HStFfPS701hQuestionaryWySNk6"

This is a multi-part message in MIME format.

----KCMailC68HStFfPS701hQuestionaryWySNk6
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1187.37">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
</style>
</head>
<body>
<p class="p1">TestText</p>
</body>
</html>


----KCMailC68HStFfPS701hQuestionaryWySNk6
Content-Type: text/plain;
     name="splittet Kopie.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;    filename="splittet Kopie.txt"

RGllcyBpc3QgZWluIFRlc3QtVGV4dA==

--KCMailC68HStFfPS701hQuestionaryWySNk6--
.

The base64 string is decoded: Dies ist ein Test-Text (This is a test text)
If I open the attachment it looks like this:

 <br>
Dies ist ein Test-Tex--KCMailC68HStFfPS701hQuestionaryWySNk6--t

The line breaks are all \r\n and if I send a different attachment like a PDF I get this boundary in the document. Any ideas what it could be? (Everything else is working)


Solution

  • Your last boundary is missing two leading hyphens

    --KCMailC68HStFfPS701hQuestionaryWySNk6--
    

    Try changing it to

    ----KCMailC68HStFfPS701hQuestionaryWySNk6--
    

    (and the email is missing a Date-Header, not the cause of your current problem, but your next one if you don't add it ;-) )