Mercurial > thymian
comparison 3rdparty/vmime/examples/example1.cpp @ 0:a4671277546c tip
created the repository for the thymian project
| author | ferencd |
|---|---|
| date | Tue, 17 Aug 2021 11:19:54 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4671277546c |
|---|---|
| 1 // | |
| 2 // VMime library (http://www.vmime.org) | |
| 3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org> | |
| 4 // | |
| 5 // This program is free software; you can redistribute it and/or | |
| 6 // modify it under the terms of the GNU General Public License as | |
| 7 // published by the Free Software Foundation; either version 3 of | |
| 8 // the License, or (at your option) any later version. | |
| 9 // | |
| 10 // This program is distributed in the hope that it will be useful, | |
| 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 // General Public License for more details. | |
| 14 // | |
| 15 // You should have received a copy of the GNU General Public License along | |
| 16 // with this program; if not, write to the Free Software Foundation, Inc., | |
| 17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 18 // | |
| 19 // Linking this library statically or dynamically with other modules is making | |
| 20 // a combined work based on this library. Thus, the terms and conditions of | |
| 21 // the GNU General Public License cover the whole combination. | |
| 22 // | |
| 23 | |
| 24 // | |
| 25 // EXAMPLE DESCRIPTION: | |
| 26 // ==================== | |
| 27 // This sample program demonstrate the use of the messageBuilder component | |
| 28 // to build a simple message. | |
| 29 // | |
| 30 // For more information, please visit: | |
| 31 // http://www.vmime.org/ | |
| 32 // | |
| 33 | |
| 34 #include <iostream> | |
| 35 #include <locale> | |
| 36 #include <clocale> | |
| 37 | |
| 38 #include "vmime/vmime.hpp" | |
| 39 #include "vmime/platforms/posix/posixHandler.hpp" | |
| 40 | |
| 41 | |
| 42 int main() | |
| 43 { | |
| 44 std::cout << std::endl; | |
| 45 | |
| 46 // Set the global C and C++ locale to the user-configured locale. | |
| 47 // The locale should use UTF-8 encoding for these tests to run successfully. | |
| 48 try | |
| 49 { | |
| 50 std::locale::global(std::locale("")); | |
| 51 } | |
| 52 catch (std::exception &) | |
| 53 { | |
| 54 std::setlocale(LC_ALL, ""); | |
| 55 } | |
| 56 | |
| 57 try | |
| 58 { | |
| 59 vmime::messageBuilder mb; | |
| 60 | |
| 61 // Fill in the basic fields | |
| 62 mb.setExpeditor(vmime::mailbox("me@somewhere.com")); | |
| 63 | |
| 64 vmime::addressList to; | |
| 65 to.appendAddress(vmime::make_shared <vmime::mailbox>("you@elsewhere.com")); | |
| 66 | |
| 67 mb.setRecipients(to); | |
| 68 | |
| 69 vmime::addressList bcc; | |
| 70 bcc.appendAddress(vmime::make_shared <vmime::mailbox>("you-bcc@nowhere.com")); | |
| 71 | |
| 72 mb.setBlindCopyRecipients(bcc); | |
| 73 | |
| 74 mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder")); | |
| 75 | |
| 76 // Message body | |
| 77 mb.getTextPart()->setText(vmime::make_shared <vmime::stringContentHandler>( | |
| 78 "I'm writing this short text to test message construction " \ | |
| 79 "using the vmime::messageBuilder component.")); | |
| 80 | |
| 81 // Construction | |
| 82 vmime::shared_ptr <vmime::message> msg = mb.construct(); | |
| 83 | |
| 84 // Raw text generation | |
| 85 std::cout << "Generated message:" << std::endl; | |
| 86 std::cout << "==================" << std::endl; | |
| 87 | |
| 88 vmime::utility::outputStreamAdapter out(std::cout); | |
| 89 msg->generate(out); | |
| 90 } | |
| 91 // VMime exception | |
| 92 catch (vmime::exception& e) | |
| 93 { | |
| 94 std::cout << "vmime::exception: " << e.what() << std::endl; | |
| 95 throw; | |
| 96 } | |
| 97 // Standard exception | |
| 98 catch (std::exception& e) | |
| 99 { | |
| 100 std::cout << "std::exception: " << e.what() << std::endl; | |
| 101 //throw; | |
| 102 } | |
| 103 | |
| 104 std::cout << std::endl; | |
| 105 } | |
| 106 |
