BREW POP / SMTP Mailer - 4 / 6 -
Sending Mail
The SFXSMTPSender class is used to send mail.
class SendingWindow : public SFRTitleWindow {
private:
SFXSMTPSender _sender;
...
}
Handler for the "Send Mail" button of SendingWindow
Information is set on the SMTP server by the SetServer() function. Mail messages are made by the SFXMailMessage class and sent by the SendMessage() function.
An SMTPCallback function should be set as the argument of SendMessage().
HANDLER_IMPLEMENT_VOIDCONTROL(SendingWindow, OnButtonControlOk, result, control)
{
SFCError error;
// Setup data is obtained from the application class.
SFXConfigPtr option = SimpleMailer::GetOption();
// Class that shows mail message
SFXMailMessage message;
// Setting of "From" address
message.SetFromField(_textControlFrom->GetText());
// Setting of "To" address
message.AddToField(_textControlTo->GetText());
// Setting of "Subject"
message.SetSubjectField(_textControlSubject->GetText());
// Setting of message "Body"
message.SetBody(_textControlBody->GetText());
// Setting of address and port number of SMTP server
// Domain name is automatically resolved
_sender.SetServer(SFXSocketAddress(
option->ReadSFXAnsiString(OPTION_SMTPSERVER, ""),
option->ReadUInt16(OPTION_SMTPPOPT, 25)));
// Send mail & register "SMTPCallback" function
error = _sender.SendMessage(&message, CALLBACK_FUNCTION(SMTPCallback));
if (error == SFERR_NO_ERROR) { // if no error
// Make dialog
_dialog = ::new SFRMessageDialog(SFXGraphics::GetDeviceRectangle()
.Deflate(20, 100), "Sending...", "");
}
else {
// Make dialog
_dialog = ::new SFRMessageDialog(SFXGraphics::GetDeviceRectangle()
.Deflate(20, 100), "Fail in sending", "OK");
if (_dialog != null) {
// Register dialog hondler
_dialog->RegisterHandler(SREVT_DIALOG, HANDLER_BEFORE,
HANDLER_FUNCTION(OnDialog));
}
}
}
Declare and Define "SMTPCallback" function for sending mail
Declare
class SendingWindow : public SFRTitleWindow {
private:
...
CALLBACK_DECLARE_SFXSMTPSENDER(SMTPCallback)
...
}
Define
CALLBACK_IMPLEMENT_SFXSMTPSENDER(SendingWindow, SMTPCallback, error)
{
SFXWideString message;
if (error == SFERR_NO_ERROR) {
message.Set("Succeeded in sending");
}
else {
message.Set("Failed in sending");
}
if (_dialog != null) {
// close "Sending..." dialog
_dialog->Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE,
SRP16_TERMINATE_INVOKE, true));
}
// make dialog
_dialog = ::new SFRMessageDialog(SFXGraphics::GetDeviceRectangle()
.Deflate(20, 100), message, "OK");
if (_dialog != null) {
// Registration of dialog handler
_dialog->RegisterHandler(SREVT_DIALOG, HANDLER_BEFORE,
HANDLER_FUNCTION(OnDialog));
}
// Redrawing
SFRApplication::GetInstance()->Invoke(
SFXEvent(SREVT_RESPONDER_RENDER, SRP16_RENDER_INVOKE, false));
}







