C++에 대한 Aspose.Email FOSS를 시작하는 방법
Aspose.Email FOSS for C++ is a library for reading and writing Outlook MSG files, EML messages, and CFB containers. It has no third-party dependencies and requires only a C++17 compiler and CMake.
단계 1 - CMake 프로젝트에 클론 및 추가
git clone https://github.com/aspose-email-foss/Aspose.Email-FOSS-for-Cpp.git도서관을 하위 디렉토리로 추가하고 당신의 CMakeLists.txt:
add_subdirectory(Aspose.Email-FOSS-for-Cpp)
target_link_libraries(your_target PRIVATE AsposeEmailFoss::AsposeEmailFoss)도서관은 C++ 표준 라이브러리만 사용하고 제 3 자 의존성이 없습니다. GCC 9+, Clang 10+, MSVC 2019+는 README 프로젝트에서 지원되는 것으로 보고되었습니다.
단계 2 - MSG 파일을 읽으십시오.
포함된 것들 mapi_message 헤드 및 파일을 열기 mapi_message::from_stream():
#include <fstream>
#include <iostream>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
std::ifstream input("sample.msg", std::ios::binary);
auto message = aspose::email::foss::msg::mapi_message::from_stream(input);
std::cout << "Subject: " << message.subject() << '\n';
std::cout << "From: " << message.sender_email_address() << '\n';
std::cout << "Body: " << message.body() << '\n';
for (const auto& recipient : message.recipients())
std::cout << "To: " << recipient.email_address << '\n';
for (const auto& attachment : message.attachments())
std::cout << "Attachment: " << attachment.filename
<< " (" << attachment.mime_type << ")\n";
}mapi_message::from_stream() MSG 파일의 CFB 컨테이너를 파시하고 모든 MAPI를 표시합니다. 문자열 액세서리 방법을 통해 속성.Microsoft Outlook 설치가 필요하지 않습니다.
단계 3 - 새로운 MSG 파일 만들기
사용하기 mapi_message::create() 메시지를 기억에 만들기 위해, 보내기 및 수신자를 설정합니다. , 그리고 디스크에 저장하는 save():
#include <fstream>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
auto message = aspose::email::foss::msg::mapi_message::create(
"Meeting Notes", "Please find the agenda attached.");
message.set_sender_name("Alice");
message.set_sender_email_address("alice@example.com");
message.add_recipient("bob@example.com", "Bob");
message.add_attachment(
"agenda.txt",
std::vector<std::uint8_t>{'I', 't', 'e', 'm', ' ', '1'},
"text/plain");
std::ofstream output("meeting_notes.msg", std::ios::binary);
message.save(output);
}mapi_message::create() 기억 속에 메시지를 전달한다. save() 파일이 흐르는 길, 하나의 std::ostream,[중고] 아니면 반환하지 않음 (A) std::vector<std::uint8_t>).
단계 4 - EML을 MSG로 변환 (그리고 뒤로)
EML 파일을 사용하여 다운로드합니다. mapi_message::load_from_eml(),다음은 MSG에 대한 자세한 내용입니다. save().라운드 트립은 주제, 평면 텍스트 몸, HTML 몸 속성을 보존합니다., 배송자, 수신자 및 첨부 파일:
#include <filesystem>
#include <iostream>
#include "aspose/email/foss/msg/mapi_message.hpp"
int main()
{
// EML → MSG
auto message = aspose::email::foss::msg::mapi_message::load_from_eml(
std::filesystem::path("message.eml"));
std::cout << "Subject: " << message.subject() << '\n';
message.save(std::filesystem::path("converted.msg"));
// MSG → EML round-trip
auto loaded = aspose::email::foss::msg::mapi_message::from_file(
std::filesystem::path("converted.msg"));
loaded.save_to_eml(std::filesystem::path("roundtrip.eml"));
std::cout << "Saved converted.msg and roundtrip.eml\n";
}일반적인 문제와 해결책
바이너리 모드는 스트림에 설정되지 않습니다. 파일을 열어주고 있는 것과 함께 std::ifstream input("file.msg") 없이는 std::ios::binary CFB를 파괴하는 Windows 라인 엔드 번역을 일으킬 수 있습니다. 컨테이너 - 패스 std::ios::binary 입력 및 출력 스트림 모두를 위해.
왼쪽 오류 : AsposeEmailFoss::AsposeEmailFoss 찾을 수 없음. 확인해 보세요 이거 add_subdirectory(Aspose.Email-FOSS-for-Cpp) 이전에 나타나기 target_link_libraries(...) 당신의 안에서 CMakeLists.txt,이 이름은 부사장의 이름이다. 클론된 폴더를 정확하게 맞추고 있습니다.
C++17은 사용하지 않습니다. 도서관에는 C++17 기능이 필요합니다. 컴파일러가 오류를 보고하는 경우 구조화된 링크 또는 std::filesystem,추가하기 set(CMAKE_CXX_STANDARD 17) 에 대 한 The 당신의 위에 있는 CMakeLists.txt 이전에 The add_subdirectory 전화가 돼요.
읽기 후 빈 주제 또는 몸. 일부 MSG 파일은 Unicode 속성에 텍스트를 저장합니다. 다른 사람들은 ANSI 코드 페이지 속성을 사용합니다. message.subject() 그리고 message.body() 모든 저장소가 존재하는 링크를 반환합니다; 확인 message.html_body() 만약 message.body() 텅 비어있다.
load_from_eml 잘못된 EML에 던져진다. EML 파일이 RFC 5322를 사용하는지 확인합니다. 라인 끝 (CRLF) 및 유효한 MIME 헤드셋이 있습니다. 도서관은 조용히 멈추지 않습니다 잘못된 헤드셋.
자주 묻는 질문들
도서관은 Microsoft Outlook 또는 COM 구성 요소가 필요합니까?
Aspose.Email FOSS for C++는 자신의 CFB 및 MAPI 파세어를 사용하고 제 3 자 의존성이 없습니다.그것은 Outlook 설치없이 Linux, macOS 및 Windows에서 작동합니다.
어떤 형식으로 읽고 쓰는가?
MSG (Outlook 메시지), EML (RFC 5322 / MIME) 및 CFB (Compound File Binary)는 읽기와 쓰기에 모두 지원됩니다. TNEF (winmail.dat), IMAP, SMTP, POP3는 지원되지 않습니다.
어떻게 파일 대신 바이트로 메시지를 저장할 수 있습니까?
전화기 save() 또는 save_to_eml() 이 없어 두 번 돌아오는 것 같아요~ std::vector<std::uint8_t>, 당신은 어떤 버퍼 또는 스트림에 글을 쓸 수 있습니다.
어떤 C++ 표준이 필요합니까?
C++17 도서관은 사용하는 std::filesystem, std::optional,다른 C++17 GCC 9+, Clang 10+ 및 MSVC 2019+는 지원되는 것으로 나열되어 있습니다. 프로젝트가 준비되어 있습니다.
패키지 관리자 출시가 있습니까 (vcpkg, Conan)?
버전 0.1.0은 출처를 통해서만 배포됩니다. 레코더를 클론하고 사용하십시오. add_subdirectory 위에서 보여준 것처럼 패키지 관리자 매니저는 미래에 추가될 수 있습니다. 릴리스를 해제합니다.