login about faq

Hi,

I just upgraded to the current Ck library (16 june, VC6 release) and am having trouble when I attach a file to an email. It looks like the email message body is contained in the file attachment.

A sample program is below:

   CkEmail emailToSend;
    emailToSend.put_Charset("utf-8");
    emailToSend.put_From("<me@example.com>");
    emailToSend.put_ReplyTo("<me@example.com>");
    emailToSend.AddMultipleTo("<myemail@gmail.com>");

emailToSend.put_Subject("cktest email");
CkString ctype;
fprintf(stdout, "addfileattach: %i\n", emailToSend.AddFileAttachment("c:\\temp\\attachme.txt", ctype));
emailToSend.put_Body("hello this is a cktest email");

fprintf(stdout, "sendemail: %i\n", _mailManager.SendEmail(emailToSend));
emailToSend.SaveEml("C:\\temp\\ckemail.eml");

There aree no errors reported. The contents of the saved eml is here:

MIME-Version: 1.0
Date: Tue, 26 Jul 2016 08:33:24 +0200
Message-ID: <8574E82A40D05EACBBE772364FFDD5FAF89A0CD6@WD4VPC>
Content-Type: multipart/mixed; boundary="------------050101090505080405050107"
X-Priority: 3 (Normal)
From: ........
CKX-Bounce-Address: ........
Reply-To: ........
To: .......
Subject: cktest email

--------------050101090505080405050107
Content-Type: text/plain; charset=utf-8; name="attachme.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="attachme.txt"

hello this is a cktest email
--------------050101090505080405050107--

As you can see the text "hello this is a cktest email" appears as the content of the attached file. This was the text I added as the message body.

The real content of the attached file (attachme.txt) is nowhere to be found inside the eml.

asked Jul 26 at 02:43

Gert's gravatar image

Gert ♦
629141824


Examine the emailToSend.lastErrorText() after calling emailToSend.AddFileAttachment()

link

answered Jul 26 at 18:14

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

When I revert to an older release (the previous from a few months ago I believe) I dont see this problem.

I added mailManager.put_VerboseLogging(true); and emailToSend.put_VerboseLogging(true); and fprintf(stdout, "lasterror after attachn%sn", emailToSend.lastErrorText()); immediatly after emailToSend.AddFileAttachment and fprintf(stdout, "lasterror after SendEmailn%sn", mailManager.lastErrorText()); immediately after mailManager.SendEmail

The eml is still the same (the message body of the email is inside the attached file, the attached file contents are not inside the eml). The received email shows the same issue.

Here is the output of the program:

addfileattach: 1
lasterror after attach
ChilkatLog:
  AddFileAttachment(10ms):
    DllDate: Jun 14 2016
    ChilkatVersion: 9.5.0.58
    UnlockPrefix: WATCHDMAILQ
    Architecture: Little Endian; 32-bit
    Language: Visual C++ 6.0
    VerboseLogging: 1
    path: C:tempattachme.txt
    contentType: text/plain
    Success.
  --AddFileAttachment
--ChilkatLog

sendemail: 1 lasterror after SendEmail ChilkatLog: SendEmail(941ms): DllDate: Jun 14 2016 ChilkatVersion: 9.5.0.58 UnlockPrefix: WATCHDMAILQ Architecture: Little Endian; 32-bit Language: Visual C++ 6.0 VerboseLogging: 1 sendEmailInner(941ms): getSmtpReversePath: fromCkxBounceAddr: gert@xxxxx.net --getSmtpReversePath renderToMime: createEmailForSending: xSigningAlg: sha1 Auto-generating Message-ID clone2: assembleMimeBody: contentType: multipart/mixed isEmailAttachment: attachmentReason: contentType: multipart/mixed subject: cktest email from: gert@xxxxx.net No (multipart enclosure) --attachmentReason --isEmailAttachment assembleMimeBody: contentType: text/plain isEmailAttachment: attachmentReason: contentType: text/plain disposition: attachment filename: attachme.txt name: attachme.txt Yes (disposition=attachment) --attachmentReason --isEmailAttachment getEncodedBody: contentType: text/plain --getEncodedBody --assembleMimeBody --assembleMimeBody --clone2 --createEmailForSending assembleMimeBody: contentType: multipart/mixed isEmailAttachment: attachmentReason: contentType: multipart/mixed subject: cktest email from: gert@xxxxx.net No (multipart enclosure) --attachmentReason --isEmailAttachment assembleMimeBody: contentType: text/plain isEmailAttachment: attachmentReason: contentType: text/plain disposition: attachment filename: attachme.txt name: attachme.txt Yes (disposition=attachment) --attachmentReason --isEmailAttachment getEncodedBody: contentType: text/plain --getEncodedBody --assembleMimeBody Email assembled. --assembleMimeBody renderToMime: Elapsed time: 0 millisec --renderToMime sendMimeInner(941ms): ensureSmtpSession: ensureSmtpConnection: SmtpHost: mail.xxxxx.net SmtpPort: 26 SmtpUsername: x SmtpSsl: 0 StartTLS: 0 smtpConnect: smtpHostname: mail.xxxxx.net smtpPort: 26 connectionIsReady: Using existing/open SMTP connection to send email. --connectionIsReady ConnectionType: Unencrypted TCP/IP --smtpConnect --ensureSmtpConnection --ensureSmtpSession sendSmtpEmail(941ms): sendWithPipelining(110ms): sendMailFrom: mailFrom: gert@xxxxx.net sendCmdToSmtp: SmtpCmdSent: MAIL FROM:<gert@xxxxxxx.net><crlf> --sendCmdToSmtp --sendMailFrom sendRcptTo: sendCmdToSmtp: SmtpCmdSent: RCPT TO:<????@gmail.com><crlf> --sendCmdToSmtp --sendRcptTo sendCmdToSmtp: SmtpCmdSent: DATA<crlf> --sendCmdToSmtp readSmtpResponse(110ms): SmtpCmdResp: 250 OK --readSmtpResponse readRcptTo: readSmtpResponse: SmtpCmdResp: 250 Accepted --readSmtpResponse recipient: ?????@gmail.com --readRcptTo readSmtpResponse: SmtpCmdResp: 354 Enter message, ending with "." on a line by itsel f --readSmtpResponse --sendWithPipelining mimeDataSize: 618 sendDataToSmtp: numBytesSent: 618 --sendDataToSmtp sendCmdToSmtp: SmtpCmdSent: <crlf>.<crlf> --sendCmdToSmtp readSmtpResponse(831ms): SmtpCmdResp: 250 OK id=1bSS4X-0018c7-BT --readSmtpResponse --sendSmtpEmail --sendMimeInner --sendEmailInner Success. --SendEmail --ChilkatLog

Press any key to continue

link

answered Jul 27 at 13:05

Gert's gravatar image

Gert ♦
629141824

I'm still not able to reproduce the problem.

Since I can't get a new VC++ 6.0 build out soon, try reversing the order by setting the Body first, then add the attachment. See if that solves the problem..

link

answered Jul 27 at 13:16

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Also... I think I see the problem.

This problem would not happen with attachments that are not text/plain. You added the attachment first, and since it was a .txt, this got the Content-Type "text/plain". Given that there is no body yet, Chilkat does NOT automatically make it a multipart/mixed (as it may have before). Then... when you set the Body property, it replaces the default body, which happens to be the body of the main part of the email because it's already text/plain. Had it been something else, such as image/jpg, then Chilkat would've automatically restructured the email to multipart/mixed...

link

answered Jul 27 at 13:20

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Changing the program so it adds the body first, before the attachment fixes it. I trust the next CK release will work "the old way" (or better "both ways") again, thank you Matt.

MIME-Version: 1.0
Date: Wed, 27 Jul 2016 19:31:42 +0200
Message-ID: <da4ddb1377ab928edaa61ff74c2165f25dec90fe@wd4vpc>
Content-Type: multipart/mixed; boundary="------------010503050009040608050406"
X-Priority: 3 (Normal)
From: someone@xxx.net
CKX-Bounce-Address: someone@xxx.net
Reply-To: someone@xxx.net
To: xxx@gmail.com
Subject: cktest email

--------------010503050009040608050406
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

hello this is a cktest email
--------------010503050009040608050406
Content-Type: text/plain; name="attachme.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="attachme.txt"

file to attach
to
the email

--------------010503050009040608050406--
link

answered Jul 27 at 13:36

Gert's gravatar image

Gert ♦
629141824

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×14
×3

Asked: Jul 26 at 02:43

Seen: 287 times

Last updated: Jul 27 at 13:36

powered by OSQA