MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / SendEmailTestMessage

Method SendEmailTestMessage

src/tripwire/twcmdlineutil.cpp:708–763  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706
707
708bool cTWCmdLineUtil::SendEmailTestMessage(const TSTRING& mAddress, const cTWModeCommon* modeCommon)
709{
710 TW_UNIQUE_PTR<cMailMessage> reportMail;
711
712 // allocate the right kind of emailer object based on what came out of the config file.
713 switch (modeCommon->mMailMethod)
714 {
715#if SUPPORTS_NETWORKING
716 case cMailMessage::MAIL_BY_SMTP:
717 reportMail = TW_UNIQUE_PTR<cMailMessage>(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort));
718 break;
719#endif
720 case cMailMessage::MAIL_BY_PIPE:
721 reportMail = TW_UNIQUE_PTR<cMailMessage>(new cPipedMailMessage(modeCommon->mMailProgram));
722 break;
723 default:
724 return false;
725 }
726
727
728 // print message that we're emailing to this specific recipient
729 iUserNotify::GetInstance()->Notify(iUserNotify::V_NORMAL,
730 _T("%s %s\n"),
731 TSS_GetString(cTripwire, tripwire::STR_TEST_EMAIL_TO).c_str(),
732 cDisplayEncoder::EncodeInline(mAddress).c_str());
733
734 // send the report
735 try
736 {
737 // set up the cMailMessage class, and send it
738 reportMail->AddRecipient(mAddress);
739
740 if (!modeCommon->mMailFrom.empty())
741 reportMail->SetFrom(modeCommon->mMailFrom);
742 else
743 {
744 TSTRING machineName;
745 iFSServices::GetInstance()->GetMachineNameFullyQualified(machineName);
746 reportMail->SetFrom(TSS_GetString(cTripwire, tripwire::STR_EMAIL_FROM) + machineName);
747 }
748
749 reportMail->SetFromName(TSS_GetString(cTW, tw::STR_TSS_PRODUCT_NAME));
750
751 reportMail->SetSubject(TSS_GetString(cTripwire, tripwire::STR_TEST_EMAIL_SUBJECT));
752 reportMail->SetBody(TSS_GetString(cTripwire, tripwire::STR_TEST_EMAIL_BODY));
753 reportMail->Send();
754 }
755 catch (eError& e)
756 {
757 cTWUtil::PrintErrorMsg(e);
758 TCERR << TSS_GetString(cTripwire, tripwire::STR_ERR_EMAIL_TEST) << std::endl;
759 return false;
760 }
761
762 return true;
763}

Callers

nothing calls this directly

Calls 10

NotifyMethod · 0.80
c_strMethod · 0.80
AddRecipientMethod · 0.80
emptyMethod · 0.80
SetFromMethod · 0.80
SetFromNameMethod · 0.80
SetSubjectMethod · 0.80
SetBodyMethod · 0.80
SendMethod · 0.45

Tested by

no test coverage detected