0

Задача - получить тело сообщения с ящика mail.ru пишу:

procedure TMainForm.Button_testimapClick(Sender: TObject);
var
  MsgCnt, i: integer;
  msg: TIdMessage;
begin
  try
    LoadMailSettings('imap');
    msg := TIdMessage.Create(nil);
    msg.CharSet := 'windows-1251';
    msg.ContentType := 'text/plain; charset="windows-1251"';
MainImap.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(MainImap);
MainImap.UseTLS := utUseImplicitTLS;
MainImap.Connect;

MainImap.SelectMailBox('INBOX');
MsgCnt := MainImap.MailBox.TotalMsgs;

for i := MsgCnt downto 1 do
begin
  MainImap.Retrieve(i, msg);
  if msg.Subject <> '' then
  begin
    Memo_mail.Lines.Add(msg.Subject);
    Memo_mail.lines.AddStrings(msg.Body);
  end;

end;

MainImap.Disconnect;
MainImap.IOHandler.Free;
msg.free;


except
    on e: Exception do
      ShowMessage('Error!');
  end;

end;

Все работает без ошибок ибо тут их невозможно сделать. НО! у меня в ящике есть письма в формате html типа рассылок mail.ru и их тело из msg.Body прекрасно добавляется в мемо -т.е. чтение есть. ок.

Шлю письмо с gmail ящика себе с обычным текстом, получаю его, делает msg.Body и пустота. Где я накосячил?

1
  • ну и в догонку- служебные заголовки на почтовике подсказали что multipart/alternative у него сидит
    – Dee63
    20 апр 2015 в 19:44

1 ответ 1

0

Из справки indy: When ContentType contains a value in the "multipart/*" MIME family, use MessageParts to access the TIdText or TIdAttachment instances that make up the message.
Т.е. Вам надо использовать msg.MessageParts

3
  • Тоже дошел до этого. вот что получилось for j:=0 to msg.MessageParts.Count-1 do begin (msg.MessageParts[j] as TIdText) дальше не пойму что брать
    – Dee63
    20 апр 2015 в 20:18
  • Примерно так: if msg.MessageParts.TextPartCount > 0 then begin for PartIndex := 0 to msg.MessageParts.Count - 1 do if msgObject.MessageParts[PartIndex] is TIdText then Memo_mail.lines.AddStrings(TIdText(msg.MessageParts[PartIndex]).Body.Text); end else Memo_mail.lines.AddStrings(msg.Body.Text);
    – Tunker
    20 апр 2015 в 20:31
  • Спасибо за помощь!
    – Dee63
    21 апр 2015 в 15:41

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.