1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| - In Indy 10, you do the same things, except that you use TIdAttachmentFile
or TIdAttachmentMemory instead of TIdAttachment, and there are extra steps
involved to set up the TIdText and TIdAttachmentFile/Memory instances
properly. Every message part has a ParentPart property that is set to -1 by
default. This is an index to the part that is the "parent" of the current
part. This is for nesting parts underneath each other. -1 means that a part
is not nested, but is at the top-level of the message. Because of this
nesting support, you end up with a variety of different setups depending on
what exactly you want to send, as outlined below:
When including just HTML and no plain-text or attachments, put the HTML in
the TIdMessage.Body and set the TIdMessage.ContentType to 'text/html'.
When including just plain-text and HTML parts and no attachments, leave the
ParentPart properties set to -1, and set the TIdMessage.ContentType to
'multipart/alternative'. You end up with the following TIdMessage layout:
TIdMessage (multipart/alternative)
{
TIdText (text/plain), ParentPart -1
TIdText (text/html), ParentPart -1
}
When including just HTML and non-related attachments, leave the ParentPart
properties set to -1, and set the TIdMessage.ContentType to
'multipart/mixed'. You end up with the following TIdMessage layout:
TIdMessage (multipart/mixed)
{
TIdText (text/html), ParentPart -1
TIdAttachment (whatever), ParentPart -1
}
When including just HTML and related attachments, leave the ParentPart
properties set to -1, and set the TIdMessage.ContentType to
'multipart/related'. You end up with the following TIdMessage layout:
TIdMessage (multipart/related)
{
TIdText (text/html), ParentPart -1
TIdAttachment (image/*) ParentPart -1
}
When including both plain-text and HTML and attachments, the layout depends
on whether you are including HTML-related attachments or not:
If you are including just related attachments, then you leave the ParentPart
for the 'text/plain' part set to -1, then you need an extra blank TIdText
with its ContentType set to 'multipart/related' and the ParentPart for the
'text/html' part and attachments set to the index of of the
'multipart/related' part, and then set the TIdMessage.ContentType to
'multipart/alternative'. You end up with the following TIdMessage layout:
TIdMessage (multipart/alternative)
{
TIdText (text/plain), ParentPart -1
TIdText (multipart/related), ParentPart -1
{
TIdText (text/html), ParentPart 1
TIdAttachment (image/*) ParentPart 1
}
}
If you are including just non-related attachments, then you need an extra
blank TIdText with its ContentType set to 'multipart/alternative' and the
ParentPart for both the 'text/plain' and 'text/html' parts set to the index
of of the 'multipart/altrnative' part, the ParentPart for the attachments
left at -1, and then set the TIdMessage.ContentType to 'multipart/mixed'.
You end up with the following TIdMessage layout:
TIdMessage (multipart/mixed)
{
TIdText (multipart/alternative), ParentPart -1
{
TIdText (text/plain), ParentPart 0
TIdText (text/html), ParentPart 0
}
TIdAttachment (whatever) ParentPart -1
}
If you are including both related and non-related attachments, then you
combine the two layous above. The TIdMessage.ContentType should be set to
'multipart/mixed'. You end up with the following TIdMessage layout:
TIdMessage (multipart/mixed)
{
TIdText (multipart/alternative), ParentPart -1
{
TIdText (text/plain), ParentPart 0
TIdText (multipart/related), ParentPart 0
{
TIdText (text/html), ParentPart 2
TIdAttachment (image/*) ParentPart 2
}
}
TIdAttachment (whatever) ParentPart -1
}
Gambit |
Partager