1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
// Note that the only valid version of the GPL as far as jwSMTP
// is concerned is v2 of the license (ie v2, not v2.2 or v3.x or whatever),
// unless explicitly otherwise stated.
//
// This file is part of the jwSMTP library.
//
// jwSMTP library is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// jwSMTP library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with jwSMTP library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// jwSMTP library
// http://johnwiggins.net
// smtplib@johnwiggins.net
//
// http://www.boost.org
//#include <boost\thread\thread.hpp>
#include <iostream>
#include "jwsmtp/jwsmtp.h"
using std::cout;
using std::cin;
using std::string;
void Usage() {
cout << "jwSMTP library demo program\n"
"demo2 <email toaddress> <email fromaddress> <smtpserver>\n"
" e.g.\n"
" demo2 recipient@there.com me@server.com mail.server.com\n";
}
int main(int argc, char* argv[])
{
if(argc != 4) {
Usage();
return 0;
}
cout << "jwSMTP library demo program\n\n";
string to(argv[1]);
string from(argv[2]);
string smtpserver(argv[3]);
if(to.length() < 2 || from.length() < 2 || smtpserver.length() < 2) {
Usage();
return 0;
}
char str[2048];
cout << "Please enter the subject of the mail\n";
cin.getline(str, 500);
string subject(str);
strcpy(str, "");
cout << "Please enter the message body end with \".\" on a line by itself\n";
string mailmessage;
while(true) {
cin.getline(str, 2048);
if(!strcmp(str, "."))
break;
mailmessage += str;
mailmessage += "\r\n";
strcpy(str, "");
}
cout << "\nPlease wait sending mail\n";
// This is how to tell the mailer class that we are using a direct smtp server
// preventing the code from doing an MX lookup on 'smtpserver' i.e. passing
// false as the last parameter.
jwsmtp::mailer mail(to.c_str(), from.c_str(), subject.c_str(), mailmessage.c_str(),
smtpserver.c_str(), jwsmtp::mailer::SMTP_PORT, false);
// using a local file as opposed to a full path.
mail.attach("attach.png");
// add another recipient (carbon copy)
//mail.addrecipient("someoneelse@somewhere.net", mailer::Cc);
// set a new smtp server! This is the same as setting a nameserver.
// this depends on the constructor call. i.e. in the constructor
// If MXLookup is true this is a nameserver
// If MXLookup is false this is an smtp server
//mail.setserver("mail.somewherefun.com");
// same again except using an IP address instead.
//mail.setserver("192.168.0.1");
// boost::thread thrd(mail);
// thrd.join(); // optional
// or:-
// Use authentication
//mail.username("testuser");
//mail.password("secret");
// LOGIN authentication by default
// if you want plain as opposed to login authentication
//mail.authtype(jwsmtp::mailer::PLAIN);
// mail.send();
mail.operator()();
cout << mail.response() << "\n";
//mail.reset(); // now we can mail someone else.
//mail.setmessage("flibbletooting");
//mail.setsubject("another message same object");
//mail.attach("/home/user1/image.gif");
// or a win example
//mail.attach("C:\\image.gif");
//mail.addrecipient("someoneelseagain@foobar.net");
//mail.operator ()();
//cout << mail.response() << "\n";
return 0;
}
|