Akonadi::MessageQueueJob Class

class Akonadi::MessageQueueJob

Provides an interface for sending email. More...

Header: #include <Akonadi/MessageQueueJob>
CMake: find_package(KPim6AkonadiMime REQUIRED)
target_link_libraries(mytarget PRIVATE KPim6::AkonadiMime)

Public Functions

MessageQueueJob(QObject *parent = nullptr)
virtual ~MessageQueueJob() override
Akonadi::AddressAttribute &addressAttribute()
Akonadi::DispatchModeAttribute &dispatchModeAttribute()
std::shared_ptr<KMime::Message> message() const
Akonadi::SentActionAttribute &sentActionAttribute()
Akonadi::SentBehaviourAttribute &sentBehaviourAttribute()
void setMessage(const std::shared_ptr<KMime::Message> &message)
Akonadi::TransportAttribute &transportAttribute()

Reimplemented Public Functions

virtual void start() override

Protected Slots

virtual void slotResult(KJob *) override

Detailed Description

This class takes a KMime::Message and some related info such as sender and recipient addresses, and places the message in the outbox. The mail dispatcher agent will then take it from there and send it.

This is the preferred way for applications to send email.

This job requires some options to be set before being started. Modify the attributes of this job to change these options.

You need to set the transport of the transport attribute, the from address of the address attribute and one of the to, cc or bcc addresses of the address attribute. Also, you need to call setMessage(). Optionally, you can change the dispatch mode attribute or the sent behaviour attribute.

Example:

MessageQueueJob *job = new MessageQueueJob( this );
job->setMessage( msg ); // msg is a Message::Ptr
job->transportAttribute().setTransportId( TransportManager::self()->defaultTransportId() );
// Use the default dispatch mode.
// Use the default sent-behaviour.
job->addressAttribute().setFrom( from ); // from is a QString
job->addressAttribute().setTo( to ); // to is a QStringList
connect( job, SIGNAL(result(KJob*)), this, SLOT(jobResult(KJob*)) );
job->start();

Author: Constantin Berzan <exit3219@gmail.com>

See also DispatchModeAttribute, SentActionAttribute, SentBehaviourAttribute, TransportAttribute, and AddressAttribute.

Member Function Documentation

[explicit] MessageQueueJob::MessageQueueJob(QObject *parent = nullptr)

Creates a new MessageQueueJob. parent the QObject parent This is not an autostarting job; you need to call start() yourself.

[override virtual noexcept] MessageQueueJob::~MessageQueueJob()

Destroys the MessageQueueJob. This job deletes itself after finishing.

Akonadi::AddressAttribute &MessageQueueJob::addressAttribute()

Returns a reference to the address attribute for this message. Modify the returned attribute to change the receivers or the from address.

Akonadi::DispatchModeAttribute &MessageQueueJob::dispatchModeAttribute()

Returns a reference to the dispatch mode attribute for this message. Modify the returned attribute to change the dispatch mode.

std::shared_ptr<KMime::Message> MessageQueueJob::message() const

Returns the message to be sent.

See also setMessage().

Akonadi::SentActionAttribute &MessageQueueJob::sentActionAttribute()

Returns a reference to the sent action attribute for this message. Modify the returned attribute to change the sent actions.

Akonadi::SentBehaviourAttribute &MessageQueueJob::sentBehaviourAttribute()

Returns a reference to the sent behaviour attribute for this message. Modify the returned attribute to change the sent behaviour.

void MessageQueueJob::setMessage(const std::shared_ptr<KMime::Message> &message)

Sets the message to be sent.

See also message().

[override virtual protected slot] void MessageQueueJob::slotResult(KJob *)

Called when the ItemCreateJob subjob finishes.

(reimplemented from KCompositeJob)

[override virtual] void MessageQueueJob::start()

Creates the item and places it in the outbox. It is now queued for sending by the mail dispatcher agent.

Akonadi::TransportAttribute &MessageQueueJob::transportAttribute()

Returns a reference to the transport attribute for this message. Modify the returned attribute to change the transport used for sending the mail.