MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
EmailServiceAPI.hpp
1 #pragma once
2 
3 #include "Export.hpp"
4 
5 #include <QString>
6 #include <QFile>
7 #include <QList>
8 
9 #include <memory>
10 
11 #include <folly/futures/Future.h>
12 
13 namespace Showcase
14 {
15 
17  struct SHOWCASE_API EmailAddress
18  {
20  QString address;
22  QString name;
23  };
24 
26  struct SHOWCASE_API EmailAttachment
27  {
29 
30  EmailAttachment(EmailAttachment && o);
31 
33  QString filename;
35  std::unique_ptr<QIODevice> device;
37  QString contentType;
38  };
39 
41  class SHOWCASE_API EmailMessage
42  {
43  public:
45  enum class RecipientType {
47  To,
49  Cc,
51  Bcc
52  };
53 
54  EmailMessage();
55  EmailMessage(EmailMessage && other);
56 
57  ~EmailMessage();
58 
61  void setSender(const EmailAddress& address);
62 
64  const EmailAddress& sender() const { return m_sender; }
65 
68  void setSubject(const QString& subject);
69 
71  const QString& subject() const { return m_subject; }
72 
74  void setContent(const QString & content);
75 
77  void addContent(const QString & content);
78 
80  const QString & content() const { return m_content; }
81 
85  void addRecipient(const EmailAddress& recipient, RecipientType type = RecipientType::To);
86 
90  const QList<EmailAddress> recipients(RecipientType type = RecipientType::To) const;
91 
96  void addAttachment(const QString& filename, std::unique_ptr<QIODevice> data, const QString& contentType = "application/octet-stream");
97 
98  const std::list<EmailAttachment>& attachments() const { return m_attachments; }
99 
100  private:
101  QList<EmailAddress> recipientListByType(RecipientType type) const;
102 
103  EmailAddress m_sender;
104  QString m_subject;
105  QString m_content;
106  QList<EmailAddress> m_recipientsTo;
107  QList<EmailAddress> m_recipientsCc;
108  QList<EmailAddress> m_recipientsBcc;
109  std::list<EmailAttachment> m_attachments;
110  };
111 
113  class SHOWCASE_API EmailServiceAPI
114  {
115  public:
116 
118  struct EmailStatus
119  {
121  bool ok = true;
123  QString errorMessage;
124  };
125 
126  virtual folly::Future<EmailStatus> queueMessage(const EmailMessage& message) = 0;
127 
129  virtual EmailMessage templateMessage() = 0;
130  };
131 
132 }