?? mailer_class.h.svn-base
字號:
#ifndef __MAILER_CLASS_H__#define __MAILER_CLASS_H__#include <string>#include <vector>#include "compat.h"class Mailer { public: /* if MXLookup is true: * 'server' is nameserver to lookup MX record by. * if MXLookup is false: * 'server' is an SMTP server which will be attempted directly for * mailing if an IP address is not found */ Mailer(const char* TOaddress, const char* FROMaddress, const char* Subject, const std::vector<char>& Message, const char* server = "127.0.0.1", // default to localhost unsigned short Port = SMTP_PORT, // default SMTP port bool MXLookup = true); Mailer(const char* TOaddress, const char* FROMaddress, const char* Subject, const char* Message, const char* server = "127.0.0.1"/*default to localhost*/, unsigned short Port = SMTP_PORT, // default SMTP port bool MXLookup = true); Mailer(bool MXLookup = false, unsigned short Port = SMTP_PORT); ~Mailer(); /* call this operator to have the mail mailed * it's for using multiple threads * * e.g.: mailer mail(args...); * boost::thread thrd(mail); // operator()() is implicitly called * thrd.join(); // if needed */ void operator()(); void send(); /* attach a file to the mail (MIME 1.0) * returns false on failed */ bool attach(const std::string &filename); /* remove an attachment from the lsit of attachments * returns false if failed */ bool removeattachment(const std::string& filename); /* set a new message (replacing the old) * returns false if newmessage is empty */ bool setmessage(const std::string &newmessage); bool setmessage(const std::vector<char>& newmessage); /* set a new HTML message (replacing the old) * returns false if newmessage is emtpy */ bool setmessageHTML(const std::string & newmessage); bool setmessageHTML(const std::vector<char> &newmessage); /* use a file for data */ bool setmessageHTMLfile(const std::string& filename); /* set a new subject for the mail (replacing the old) * returns false if newSubject is empty */ bool setsubject(const std::string &newSubject); /* sets the nameserver or smtp server to connect to dependant on the * constructor call */ bool setserver(const std::string &nameserver_or_smtpserver); /* sets the sender address */ bool setsender(const std::string& newsender); /* add a recipient to the recipient list (max. 100 recipients) */ bool addrecipient(const std::string& newrecipient, short recipient_type = TO); /* remove a recipient from the recipient list */ bool removerecipient(const std::string& recipient); /* clear all recipients from the recipient list. */ void clearrecipients(); /* clear all attachments from the mail. */ void clearattachments(); /* cleanup */ void reset(); /* returns the return code sent by the smtp server or a local error */ const std::string& response() const; /* constants - in unix we have to have a named object */ const static enum {TO, Cc, Bcc, SMTP_PORT = 25, DNS_PORT = 53} consts; /* what type of authentication are we using */ enum authtype {LOGIN = 1, PLAIN} type; /* set the auth type */ void authtype(const enum authtype Type); /* set username for auth */ void username(const std::string& User); /* set password for authentication */ void password(const std::string& Pass); private: /* create a header with current message and attachments */ std::vector<char> makesmtpmessage() const; /* one line shouldn't have more than 1000 chars in one line */ void checkRFCcompat(); /* returns the part of the string toaddress after the @ symbol */ std::string getserveraddress(const std::string& toaddress) const; /* Does the work of getting MX records for the server returned by * 'getserveraddress' will use the dns server passed to this's constructor * in 'nameserver' or if MXlookup is false in the constuctor, will return * an address for the server that 'getserveraddress' returns. */ bool gethostaddresses(std::vector<SOCKADDR_IN>& adds); /* parses a DNS Ressource Record */ bool parseRR(int& pos, const unsigned char dns[], std::string &name, in_addr &address); /* parses a dns name returned in a dns query */ void parsename(int &pos, const unsigned char dns[], std::string &name); /* email address wrapper struct */ struct Address { std::string name; // e.g. freddy foobar std::string address; // e.g. someone@mail.com }; /* authenticate against a server */ bool authenticate(const std::string& servergreeting, const SOCKET& s); typedef std::vector<std::pair<std::vector<char>, std::string> >::const_iterator vec_pair_char_str_const_iter; typedef std::vector<std::pair<Address, short> >::const_iterator recipient_const_iter; typedef std::vector<std::pair<Address, short> >::iterator recipient_iter; typedef std::vector<std::string>::const_iterator vec_str_const_iter; /* split an address into its relevant parts */ Address parseaddress(const std::string& addresstoparse); std::vector<std::pair<Address, short> > recipients; // address to send mail to Address fromAddress; // the address the mail is from std::string subject; // subject of the mail std::vector<char> message; // content of the mail message std::vector<char> messageHTML; // content of mail message in HTML std::vector<std::pair<std::vector<char>, std::string> > attachments; // attachments std::string server; // will be filled in from the toAddress by getserveraddress std::string nameserver; // name of a nameserver to query const unsigned short port; // smtp port to mail to const bool lookupMXRecord; // use dns to query for MX records bool auth; // using auth std::string user; // username for smtp auth std::string pass; // password for smtp auth std::string returnstring; // filled in with server return strings };#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -