Ejemplo n.º 1
0
void main()
{
    MUtils::WinSockHelper wshelper;
	
    // make sure the file 'boot.ini' is in the root directory on driver C
    SMailer::TextPlainContent  content1("plain text content");
    SMailer::TextHtmlContent   content2("<a href='http://morningspace.51.net'>click me</a>");
    SMailer::AppOctStrmContent content3("c:\\smtp_boot.ini");
	
    SMailer::MailInfo info;
    info.setSenderName("linshenglong888");
    info.setSenderAddress("*****@*****.**");
    info.addReceiver("linshenglong777", "*****@*****.**");
    info.addReceiver("shenglonglin1986", "*****@*****.**");
    info.setPriority(SMailer::Priority::normal);
    info.setSubject("a test mail");
    info.addMimeContent(&content1);
    info.addMimeContent(&content2);
    info.addMimeContent(&content3);
	
    try
    {
        SMailer::MailSender sender("smtp.126.com", "linshenglong888", "051335");
        sender.setMail(&SMailer::MailWrapper(&info));
        sender.sendMail();
    }
    catch (SMailer::MailException& e)
    {
        std::cout << e.what() << std::endl;
    }
    catch (...)
    {
        std::cout << "Unkown error" << std::endl;
    }
}
Ejemplo n.º 2
0
bool MySendMail::SendMail()
{
	if(!smptAddress || !content || !sendName || !senderAddress || !receiverAddress || !mailSubject
		|| !user || !password || !receiverName)
	{
		return false;
	}
	WinSockHelper wshelper;
	SMailer::TextPlainContent  mailContent(content);
	SMailer::MailInfo info;
	info.setSenderName(sendName);
    info.setSenderAddress(senderAddress);
    info.addReceiver(receiverName, receiverAddress);
    
    info.setPriority(SMailer::Priority::normal);
    info.setSubject(mailSubject);
    info.addMimeContent(&mailContent);

	try
    {
		sender.GetMailBaseInfo(smptAddress, user, password);
        sender.setMail(&SMailer::MailWrapper(&info));
        sender.sendMail();
    }
    catch (SMailer::MailException& e)
    {
		sender.quit();
        return false;
    }
    catch (...)
    {
		sender.quit();
        return false;
    }
	return true;
}