ferencd@0: // ferencd@0: // VMime library (http://www.vmime.org) ferencd@0: // Copyright (C) 2002-2013 Vincent Richard ferencd@0: // ferencd@0: // This program is free software; you can redistribute it and/or ferencd@0: // modify it under the terms of the GNU General Public License as ferencd@0: // published by the Free Software Foundation; either version 3 of ferencd@0: // the License, or (at your option) any later version. ferencd@0: // ferencd@0: // This program is distributed in the hope that it will be useful, ferencd@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of ferencd@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ferencd@0: // General Public License for more details. ferencd@0: // ferencd@0: // You should have received a copy of the GNU General Public License along ferencd@0: // with this program; if not, write to the Free Software Foundation, Inc., ferencd@0: // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ferencd@0: // ferencd@0: // Linking this library statically or dynamically with other modules is making ferencd@0: // a combined work based on this library. Thus, the terms and conditions of ferencd@0: // the GNU General Public License cover the whole combination. ferencd@0: // ferencd@0: ferencd@0: // ferencd@0: // EXAMPLE DESCRIPTION: ferencd@0: // ==================== ferencd@0: // This sample program demonstrate the use of the messageBuilder component ferencd@0: // to build a simple message. ferencd@0: // ferencd@0: // For more information, please visit: ferencd@0: // http://www.vmime.org/ ferencd@0: // ferencd@0: ferencd@0: #include ferencd@0: #include ferencd@0: #include ferencd@0: ferencd@0: #include "vmime/vmime.hpp" ferencd@0: #include "vmime/platforms/posix/posixHandler.hpp" ferencd@0: ferencd@0: ferencd@0: int main() ferencd@0: { ferencd@0: std::cout << std::endl; ferencd@0: ferencd@0: // Set the global C and C++ locale to the user-configured locale. ferencd@0: // The locale should use UTF-8 encoding for these tests to run successfully. ferencd@0: try ferencd@0: { ferencd@0: std::locale::global(std::locale("")); ferencd@0: } ferencd@0: catch (std::exception &) ferencd@0: { ferencd@0: std::setlocale(LC_ALL, ""); ferencd@0: } ferencd@0: ferencd@0: try ferencd@0: { ferencd@0: vmime::messageBuilder mb; ferencd@0: ferencd@0: // Fill in the basic fields ferencd@0: mb.setExpeditor(vmime::mailbox("me@somewhere.com")); ferencd@0: ferencd@0: vmime::addressList to; ferencd@0: to.appendAddress(vmime::make_shared ("you@elsewhere.com")); ferencd@0: ferencd@0: mb.setRecipients(to); ferencd@0: ferencd@0: vmime::addressList bcc; ferencd@0: bcc.appendAddress(vmime::make_shared ("you-bcc@nowhere.com")); ferencd@0: ferencd@0: mb.setBlindCopyRecipients(bcc); ferencd@0: ferencd@0: mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder")); ferencd@0: ferencd@0: // Message body ferencd@0: mb.getTextPart()->setText(vmime::make_shared ( ferencd@0: "I'm writing this short text to test message construction " \ ferencd@0: "using the vmime::messageBuilder component.")); ferencd@0: ferencd@0: // Construction ferencd@0: vmime::shared_ptr msg = mb.construct(); ferencd@0: ferencd@0: // Raw text generation ferencd@0: std::cout << "Generated message:" << std::endl; ferencd@0: std::cout << "==================" << std::endl; ferencd@0: ferencd@0: vmime::utility::outputStreamAdapter out(std::cout); ferencd@0: msg->generate(out); ferencd@0: } ferencd@0: // VMime exception ferencd@0: catch (vmime::exception& e) ferencd@0: { ferencd@0: std::cout << "vmime::exception: " << e.what() << std::endl; ferencd@0: throw; ferencd@0: } ferencd@0: // Standard exception ferencd@0: catch (std::exception& e) ferencd@0: { ferencd@0: std::cout << "std::exception: " << e.what() << std::endl; ferencd@0: //throw; ferencd@0: } ferencd@0: ferencd@0: std::cout << std::endl; ferencd@0: } ferencd@0: