I would suggest something more like this instead: try Now, with all of that said, there are some other minor coding issues with your use of Indy's components in general. You would simply load the file data into a TIdText instead of a TIdAttachmentFile, and then be sure to set the TIdText.ContentDisposition property to attachment (otherwise it will default to inline), and set the TIdText.FileName, so the data is still treated as an attachment by the recipient: if FileExists(PathString) thenĪttachment := TIdText.Create(IdMessage.MessageParts, nil) Ī(PathString, TEncoding.UTF8) Īttachment.ContentDisposition := 'attachment' Īttachment.FileName := ExtractFileName(PathString) If you want, you can have Indy normalize the linebreaks to CRLF. For instance, if the original file on Android is using LF linebreaks, but the recipient only supports CRLF linebreaks instead. That sounds more like a linebreak issue than an encoding issue. If you know for a fact that the file you are attaching is encoded in UTF-8, you should be explicit about it: if FileExists(PathString) thenĪttachment := TIdAttachmentFile.Create(IdMessage.MessageParts, PathString) Īnd is displaying it's content in lines next to eachother instead of underneath eachother. So it is likely that the recipient is detecting the text/plain media type with a missing charset and is displaying the file data in ASCII/ANSI because it does not know the data is actually UTF-8 encoded instead (since the file is an attachment, the recipient should be saving the raw bytes as-is if saving the attachment to a new file). Without that, the recipient will interpret the data using a default charset instead (typically us-ascii per RFC 822). media type has a charset attribute associated with it, but you are not setting the attachment's Charset property in your code. txt so the ContentType should be defaulting to text/plain. TIdAttachmentFile defaults its ContentType property value based on the extension of the filename that you pass to the constructor. Indy does not change an attached file's encoding. When using TIdAttachmentFile, the raw bytes of the file are sent as-is. txt file's encoding has changed from UTF-8 to ANSI IdEmailAddressItem.Address := AppData.MailAddrReceiver TIdAttachmentFile.Create(IdMessage.MessageParts,PathString) PathString := (, (PathString + 'Log.txt')) IdSMTP.Username := AppData.MailAddrSender SSLHandler:= TIdSSLIOHandlerSocketOpenSSL.Create(Form1) So what have I been doing wrong, and how to solve this?įunctional code used to send the mail: Body := TStringList.Create txt file's encoding has changed from UTF-8 to ANSI and is displaying it's content in lines next to eachother instead of underneath eachother. txt file as an attachment from an Android device using Indy.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |