简体   繁体   English

如何使用C ++ Builder获取电子邮件正文

[英]How to get Body of the email using c++ builder


I want to get the email body from my Gmail account for an email so i use this code i found it in an example for how to read emails using c++ builder pop3 the code to extract body used 我想从我的Gmail帐户中获取一封电子邮件的电子邮件正文,因此我使用此代码,我在一个示例中找到了该示例,该示例说明了如何使用c ++ builder pop3读取电子邮件,该代码提取了所使用的正文

TIdText *EText;
int message = SpinEdit1->Value;
MyPoP3->Retrieve(message, MyEmail);
Edit1->Text = MyEmail->Subject + " | " + MyEmail->From->Address;
Memo1->Clear();

for (int i = 0; i < MyEmail->MessageParts->Count; i++) {
    Memo1->Lines->Add(MyEmail->MessageParts->Items[i]->ContentType);
    EText = dynamic_cast<TIdText*>(MyEmail->MessageParts->Items[i]);
    Memo1->Lines->Add(EText->Body);
}

the problem is that i got undefine symbol to TidText and what i tried is to change it from TIdText to TIdMessage , but i got that i can't convert to it. 问题是,我得到取消定义符号TidText什么我想是将其从改变TIdTextTIdMessage ,但我得到了我不能转换到它。 also i tried to try this without loop or something MyEmail->Body->Text this return empty string. 我也尝试没有循环或其他MyEmail->Body->Text这返回空字符串的尝试。
the video i got this code from it here i don't know maybe the c++ builder he use is old. 我从这里得到此代码的视频我不知道他使用的c ++生成器是否旧。 now i want to know how to extract the body text from the email address. 现在我想知道如何从电子邮件地址中提取正文。
Thanks in advance. 提前致谢。

the problem is that i got undefine symbol to TidText 问题是我对TidText有未定义的符号

Your code is missing an #include <IdText.hpp> statement. 您的代码缺少#include <IdText.hpp>语句。

what i tried is to change it from TIdText to TIdMessage , but i got that i can't convert to it. 我试图将它从改变TIdTextTIdMessage ,但我得到了我不能转换到它。

Because TIdMessage does not contain nested TIdMessage objects. 因为TIdMessage不包含嵌套的TIdMessage对象。

also i tried to try this without loop or something MyEmail->Body->Text this return empty string. 我也尝试没有循环或其他MyEmail->Body->Text这返回空字符串的尝试。

If your email is MIME encoded, its text is not stored in the TIdMessage::Body property, but in a nested TIdText object within the TIdMessage::MessageParts collection. 如果您的电子邮件是MIME编码的,则其文本不会存储在TIdText TIdMessage::Body属性中,而是存储在TIdText TIdMessage::MessageParts集合内的嵌套TIdText对象中。 You have to look at the TIdMessage::ContentType property to know what kind of structure the email contains. 您必须查看TIdMessage::ContentType属性才能知道电子邮件所包含的结构类型。 For instance, if the CT begins with text/ , the text is in the TIdMessage::Body . 例如,如果CT以text/开头,则文本在TIdMessage::Body But if the CT begins with multipart/ , the text is somewhere in the TIdMessage::MessageParts instead. 但是,如果CT以multipart/开头,则文本位于TIdMessage::MessageParts

You should read this blog article on Indy's website for an example of how emails might be structured: 您应该阅读Indy网站上的博客文章,以获取有关电子邮件结构的示例:

HTML Messages HTML消息

the video i got this code from it here i don't know maybe the c++ builder he use is old. 我从这里得到此代码的视频我不知道他使用的c ++生成器是否旧。

No, it is not. 不它不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM