本文整理汇总了C++中MailMessage::addRecipient方法的典型用法代码示例。如果您正苦于以下问题:C++ MailMessage::addRecipient方法的具体用法?C++ MailMessage::addRecipient怎么用?C++ MailMessage::addRecipient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MailMessage
的用法示例。
在下文中一共展示了MailMessage::addRecipient方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char **argv)
{
try
{
MailMessage msg;
msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT,
"[email protected]",
"Alice Moralis"));
msg.addRecipient (MailRecipient (MailRecipient::CC_RECIPIENT,
"[email protected]",
"Patrick Kilpatrick"));
msg.addRecipient (MailRecipient (MailRecipient::BCC_RECIPIENT,
"[email protected]",
"Michael Carmichael"));
msg.setSender ("Roy Kilroy <[email protected]>");
msg.setSubject ("Rosetta Code");
msg.setContent ("Sending mail from C++ using POCO C++ Libraries");
SMTPClientSession smtp ("mail.example.com"); // SMTP server name
smtp.login ();
smtp.sendMessage (msg);
smtp.close ();
std::cerr << "Sent mail successfully!" << std::endl;
}
catch (std::exception &e)
{
std::cerr << "failed to send mail: " << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
示例2: testSendFailed
void SMTPClientSessionTest::testSendFailed()
{
DialogServer server;
server.addResponse("220 localhost SMTP ready");
server.addResponse("250 Hello localhost");
server.addResponse("250 OK");
server.addResponse("250 OK");
server.addResponse("354 Send data");
server.addResponse("500 Error");
server.addResponse("221 Bye");
SMTPClientSession session("localhost", server.port());
session.login("localhost");
MailMessage message;
message.setSender("[email protected]");
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "Jane Doe"));
message.setSubject("Test Message");
message.setContent("Hello\r\nblah blah\r\n\r\nJohn\r\n");
server.clearCommands();
try
{
session.sendMessage(message);
fail("internal error - must throw");
}
catch (SMTPException&)
{
}
session.close();
}
示例3: ts
void MailMessageTest::testWrite8Bit()
{
MailMessage message;
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "John Doe");
message.addRecipient(r1);
message.setSubject("Test Message");
message.setSender("[email protected]");
message.setContent(
"Hello, world!\r\n"
"This is a test for the MailMessage class.\r\n",
MailMessage::ENCODING_8BIT
);
Timestamp ts(0);
message.setDate(ts);
std::ostringstream str;
message.write(str);
std::string s = str.str();
assert (s ==
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
"Content-Type: text/plain\r\n"
"Subject: Test Message\r\n"
"From: [email protected]\r\n"
"Content-Transfer-Encoding: 8bit\r\n"
"To: John Doe <john.[email protected]>\r\n"
"\r\n"
"Hello, world!\r\n"
"This is a test for the MailMessage class.\r\n"
);
}
示例4: sendMessage
void SendMail::sendMessage(const std::string& content)
{
try {
const Poco::Util::AbstractConfiguration* config = Poco::Util::Application::instance().config().createView("ion.mail");
MailMessage message;
message.setSender(config->getString("sender"));
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, config->getString("recipient")));
message.setSubject(MailMessage::encodeWord(config->getString("subject"), "UTF-8"));
message.setContentType("text/plain; charset=UTF-8");
message.addContent(new Poco::Net::StringPartSource(content));
Poco::Net::SocketAddress address(config->getString("host"), config->getInt("port"));
Poco::SharedPtr<Poco::Net::StreamSocket> socket(nullptr);
if (config->getBool("ssl")) {
socket = new Poco::Net::SecureStreamSocket(address);
}
else {
socket = new Poco::Net::StreamSocket(address);
}
_logger.debug("Connecting to %s", address.toString());
SMTPClientSession session(*socket);
session.login(getLoginMethod(config->getString("loginmethod")), config->getString("user"), config->getString("password"));
session.sendMessage(message);
session.close();
_logger.debug("Message sent");
}
catch (Poco::Exception& ex) {
_logger.error(ex.displayText());
throw;
}
}
示例5: testWriteMultiPart
void MailMessageTest::testWriteMultiPart()
{
MailMessage message;
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "John Doe");
message.addRecipient(r1);
message.setSubject("Test Message");
message.setSender("[email protected]");
Timestamp ts(0);
message.setDate(ts);
message.addContent(new StringPartSource("Hello World!\r\n", "text/plain"), MailMessage::ENCODING_8BIT);
StringPartSource* pSPS = new StringPartSource("This is some binary data. Really.", "application/octet-stream", "sample.dat");
pSPS->headers().set("Content-ID", "abcd1234");
message.addAttachment("sample", pSPS);
assert (message.isMultipart());
std::ostringstream str;
message.write(str);
std::string s = str.str();
std::string rawMsg(
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
"Content-Type: multipart/mixed; boundary=$\r\n"
"Subject: Test Message\r\n"
"From: [email protected]\r\n"
"To: John Doe <[email protected]>\r\n"
"Mime-Version: 1.0\r\n"
"\r\n"
"--$\r\n"
"Content-Type: text/plain\r\n"
"Content-Transfer-Encoding: 8bit\r\n"
"Content-Disposition: inline\r\n"
"\r\n"
"Hello World!\r\n"
"\r\n"
"--$\r\n"
"Content-ID: abcd1234\r\n"
"Content-Type: application/octet-stream; name=sample\r\n"
"Content-Transfer-Encoding: base64\r\n"
"Content-Disposition: attachment; filename=sample.dat\r\n"
"\r\n"
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
"--$--\r\n"
);
std::string::size_type p1 = s.find('=') + 1;
std::string::size_type p2 = s.find('\r', p1);
std::string boundary(s, p1, p2 - p1);
std::string msg;
for (std::string::const_iterator it = rawMsg.begin(); it != rawMsg.end(); ++it)
{
if (*it == '$')
msg += boundary;
else
msg += *it;
}
assert (s == msg);
}
示例6: testWriteQP
void MailMessageTest::testWriteQP()
{
MailMessage message;
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "John Doe");
MailRecipient r2(MailRecipient::CC_RECIPIENT, "[email protected]", "Jane Doe");
MailRecipient r3(MailRecipient::BCC_RECIPIENT, "[email protected]", "Frank Foo");
MailRecipient r4(MailRecipient::BCC_RECIPIENT, "[email protected]", "Bernie Bar");
message.addRecipient(r1);
message.addRecipient(r2);
message.addRecipient(r3);
message.addRecipient(r4);
message.setSubject("Test Message");
message.setSender("[email protected]");
message.setContent(
"Hello, world!\r\n"
"This is a test for the MailMessage class.\r\n"
"To test the quoted-printable encoding, we'll put an extra long line here. This should be enough.\r\n"
"And here is some more =fe.\r\n"
);
Timestamp ts(0);
message.setDate(ts);
assert (!message.isMultipart());
std::ostringstream str;
message.write(str);
std::string s = str.str();
assert (s ==
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
"Content-Type: text/plain\r\n"
"Subject: Test Message\r\n"
"From: [email protected]\r\n"
"Content-Transfer-Encoding: quoted-printable\r\n"
"To: John Doe <[email protected]>\r\n"
"CC: Jane Doe <[email protected]>\r\n"
"\r\n"
"Hello, world!\r\n"
"This is a test for the MailMessage class.\r\n"
"To test the quoted-printable encoding, we'll put an extra long line here. T=\r\n"
"his should be enough.\r\n"
"And here is some more =3Dfe.\r\n"
);
}
示例7: log
void SMTPChannel::log(const Message& msg)
{
try
{
MailMessage message;
message.setSender(_sender);
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, _recipient));
message.setSubject("Log Message from " + _sender);
std::stringstream content;
content << "Log Message\r\n"
<< "===========\r\n\r\n"
<< "Host: " << Environment::nodeName() << "\r\n"
<< "Logger: " << msg.getSource() << "\r\n";
if (_local)
{
DateTime dt(msg.getTime());
content << "Timestamp: " << DateTimeFormatter::format(LocalDateTime(dt), DateTimeFormat::RFC822_FORMAT) << "\r\n";
}
else
content << "Timestamp: " << DateTimeFormatter::format(msg.getTime(), DateTimeFormat::RFC822_FORMAT) << "\r\n";
content << "Priority: " << NumberFormatter::format(msg.getPriority()) << "\r\n"
<< "Process ID: " << NumberFormatter::format(msg.getPid()) << "\r\n"
<< "Thread: " << msg.getThread() << " (ID: " << msg.getTid() << ")\r\n"
<< "Message text: " << msg.getText() << "\r\n\r\n";
message.addContent(new StringPartSource(content.str()));
if (!_attachment.empty())
{
{
Poco::FileInputStream fis(_attachment, std::ios::in | std::ios::binary | std::ios::ate);
if (fis.good())
{
int size = fis.tellg();
char* pMem = new char [size];
fis.seekg(std::ios::beg);
fis.read(pMem, size);
message.addAttachment(_attachment, new StringPartSource(std::string(pMem, size), _type, _attachment));
delete [] pMem;
}
}
if (_delete) File(_attachment).remove();
}
SMTPClientSession session(_mailHost);
session.login();
session.sendMessage(message);
session.close();
}
catch (Exception&)
{
if (_throw) throw;
}
}
示例8: main
int main(int argc, char** argv)
{
SSLInitializer sslInitializer;
if (argc < 4)
{
Path p(argv[0]);
std::cerr << "usage: " << p.getBaseName() << " <mailhost> <sender> <recipient> [<username> <password>]" << std::endl;
std::cerr << " Send an email greeting from <sender> to <recipient>," << std::endl;
std::cerr << " using a secure connection to the SMTP server at <mailhost>." << std::endl;
return 1;
}
std::string mailhost(argv[1]);
std::string sender(argv[2]);
std::string recipient(argv[3]);
std::string username(argc >= 5 ? argv[4] : "");
std::string password(argc >= 6 ? argv[5] : "");
try
{
// Note: we must create the passphrase handler prior Context
SharedPtr<InvalidCertificateHandler> pCert = new ConsoleCertificateHandler(false); // ask the user via console
Context::Ptr pContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_RELAXED, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
SSLManager::instance().initializeClient(0, pCert, pContext);
MailMessage message;
message.setSender(sender);
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, recipient));
message.setSubject("Hello from the POCO C++ Libraries");
std::string content;
content += "Hello ";
content += recipient;
content += ",\r\n\r\n";
content += "This is a greeting from the POCO C++ Libraries.\r\n\r\n";
std::string logo(reinterpret_cast<const char*>(PocoLogo), sizeof(PocoLogo));
message.addContent(new StringPartSource(content));
message.addAttachment("logo", new StringPartSource(logo, "image/gif"));
SecureSMTPClientSession session(mailhost);
session.login();
session.startTLS(pContext);
if (!username.empty())
{
session.login(SMTPClientSession::AUTH_LOGIN, username, password);
}
session.sendMessage(message);
session.close();
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
}
示例9: testWriteManyRecipients
void MailMessageTest::testWriteManyRecipients()
{
MailMessage message;
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "John Doe");
MailRecipient r2(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "Jane Doe");
MailRecipient r3(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "Frank Foo");
MailRecipient r4(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "Bernie Bar");
MailRecipient r5(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "Joe Spammer");
message.addRecipient(r1);
message.addRecipient(r2);
message.addRecipient(r3);
message.addRecipient(r4);
message.addRecipient(r5);
message.setSubject("Test Message");
message.setSender("[email protected]");
message.setContent(
"Hello, world!\r\n"
"This is a test for the MailMessage class.\r\n",
MailMessage::ENCODING_8BIT
);
Timestamp ts(0);
message.setDate(ts);
std::ostringstream str;
message.write(str);
std::string s = str.str();
assert (s ==
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
"Content-Type: text/plain\r\n"
"Subject: Test Message\r\n"
"From: [email protected]\r\n"
"Content-Transfer-Encoding: 8bit\r\n"
"To: John Doe <[email protected]>, Jane Doe <[email protected]>, \r\n"
"\tFrank Foo <[email protected]>, Bernie Bar <[email protected]>, \r\n"
"\tJoe Spammer <[email protected]>\r\n"
"\r\n"
"Hello, world!\r\n"
"This is a test for the MailMessage class.\r\n"
);
}
示例10: testSend
void SMTPClientSessionTest::testSend()
{
DialogServer server;
server.addResponse("220 localhost SMTP ready");
server.addResponse("250 Hello localhost");
server.addResponse("250 OK");
server.addResponse("250 OK");
server.addResponse("354 Send data");
server.addResponse("250 OK");
server.addResponse("221 Bye");
SMTPClientSession session("localhost", server.port());
session.login("localhost");
MailMessage message;
message.setSender("[email protected]");
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "Jane Doe"));
message.setSubject("Test Message");
message.setContent("Hello\r\nblah blah\r\n\r\nJohn\r\n");
server.clearCommands();
session.sendMessage(message);
std::string cmd = server.popCommandWait();
assert (cmd == "MAIL FROM: <[email protected]>");
cmd = server.popCommandWait();
assert (cmd == "RCPT TO: <[email protected]>");
cmd = server.popCommandWait();
assert (cmd == "DATA");
cmd = server.popCommandWait();
assert (cmd.substr(0, 4) == "Date");
cmd = server.popCommandWait();
assert (cmd == "Content-Type: text/plain");
cmd = server.popCommandWait();
assert (cmd == "From: [email protected]");
cmd = server.popCommandWait();
assert (cmd == "Subject: Test Message");
cmd = server.popCommandWait();
assert (cmd == "Content-Transfer-Encoding: quoted-printable");
cmd = server.popCommandWait();
assert (cmd == "To: Jane Doe <[email protected]>");
cmd = server.popCommandWait();
assert (cmd == "Hello");
cmd = server.popCommandWait();
assert (cmd == "blah blah");
cmd = server.popCommandWait();
assert (cmd == "John");
cmd = server.popCommandWait();
assert (cmd == ".");
session.close();
}
示例11: main
int main(int argc, char** argv)
{
if (argc != 4)
{
Path p(argv[0]);
std::cerr << "usage: " << p.getBaseName() << " <mailhost> <sender> <recipient>" << std::endl;
std::cerr << " Send an email greeting from <sender> to <recipient>," << std::endl;
std::cerr << " the SMTP server at <mailhost>." << std::endl;
return 1;
}
std::string mailhost(argv[1]);
std::string sender(argv[2]);
std::string recipient(argv[3]);
try
{
MailMessage message;
message.setSender(sender);
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, recipient));
message.setSubject("Hello from the POCO C++ Libraries");
std::string content;
content += "Hello ";
content += recipient;
content += ",\r\n\r\n";
content += "This is a greeting from the POCO C++ Libraries.\r\n\r\n";
std::string logo(reinterpret_cast<const char*>(PocoLogo), sizeof(PocoLogo));
message.addContent(new StringPartSource(content));
message.addAttachment("logo", new StringPartSource(logo, "image/gif"));
SMTPClientSession session(mailhost);
session.login();
session.sendMessage(message);
session.close();
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
}
示例12: Test_MailMessage
void Test_MailMessage()
{
std::string sender("[email protected]");
std::string recipient("[email protected]");
std::string subject("Generated email");
std::string content = "Hi ";
content += recipient;
content += ",\n\n";
content += "Have a good day!\n\n";
content += "Regards,\n";
content += "A-Team";
std::string attachment("C:\\DSC.jpg");
MailMessage message;
message.setSender( sender );
message.addRecipient( MailRecipient(MailRecipient::PRIMARY_RECIPIENT, recipient) );
message.setSubject( subject );
message.setContent( content );
message.addAttachment( attachment );
send(message);
}
示例13: main
//.........这里部分代码省略.........
obConversion.ReadFile(&obMol, (job_path / ("ligand." + format)).string());
const auto num_atoms = obMol.NumAtoms();
// obMol.AddHydrogens(); // Adding hydrogens does not seem to affect SMARTS matching.
// Classify subset atoms.
array<vector<int>, num_subsets> subsets;
for (size_t k = 0; k < num_subsets; ++k)
{
auto& subset = subsets[k];
subset.reserve(num_atoms);
OBSmartsPattern smarts;
smarts.Init(SubsetSMARTS[k]);
smarts.Match(obMol);
for (const auto& map : smarts.GetMapList())
{
subset.push_back(map.front());
}
}
const auto& subset0 = subsets.front();
// Check user-provided ligand validity.
if (subset0.empty())
{
// Record job completion time stamp.
const auto millis_since_epoch = duration_cast<std::chrono::milliseconds>(system_clock::now().time_since_epoch()).count();
conn.update(collection, BSON("_id" << _id), BSON("$set" << BSON("done" << Date_t(millis_since_epoch))));
// Send error notification email.
cout << local_time() << "Sending an error notification email to " << email << endl;
MailMessage message;
message.setSender("usr <[email protected]>");
message.setSubject("Your usr job has failed");
message.setContent("Description: " + job["description"].String() + "\nSubmitted: " + to_simple_string(ptime(epoch, boost::posix_time::milliseconds(job["submitted"].Date().millis))) + " UTC\nFailed: " + to_simple_string(ptime(epoch, boost::posix_time::milliseconds(millis_since_epoch))) + " UTC\nReason: failed to parse the provided ligand.");
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, email));
SMTPClientSession session("137.189.91.190");
session.login();
session.sendMessage(message);
session.close();
continue;
}
// Calculate the four reference points.
const auto n = subset0.size();
const auto v = 1.0 / n;
array<vector3, num_references> references{};
auto& ctd = references[0];
auto& cst = references[1];
auto& fct = references[2];
auto& ftf = references[3];
for (const auto i : subset0)
{
ctd += obMol.GetAtom(i)->GetVector();
}
ctd *= v;
double cst_dist = numeric_limits<double>::max();
double fct_dist = numeric_limits<double>::lowest();
double ftf_dist = numeric_limits<double>::lowest();
for (const auto i : subset0)
{
const auto& a = obMol.GetAtom(i)->GetVector();
const auto this_dist = a.distSq(ctd);
if (this_dist < cst_dist)
{
cst = a;
cst_dist = this_dist;
}