MailMessage.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * MailMessage.h
8  *
9  * @author Slavey Karadzhov <slaff@attachix.com>
10  *
11  ****/
12 
19 #pragma once
20 
21 #include "WString.h"
22 #include "WVector.h"
23 #include "Http/HttpHeaders.h"
24 #include <Data/WebConstants.h>
27 #include <Data/Stream/FileStream.h>
28 
29 class SmtpClient;
30 
32 {
33  friend class SmtpClient;
34 
35 public:
40 
42  {
43  for(auto& attachment : attachments) {
44  delete attachment.headers;
45  delete attachment.stream;
46  }
47  }
48 
55  MailMessage& setHeader(const String& name, const String& value)
56  {
57  headers[name] = value;
58  return *this;
59  }
60 
66 
73  MailMessage& setBody(const String& body, MimeType mime = MIME_TEXT);
74 
81  MailMessage& setBody(String&& body, MimeType mime = MIME_TEXT) noexcept;
82 
90 
97 
106 
114  MailMessage& addAttachment(IDataSourceStream* stream, const String& mime, const String& filename = "");
115 
116 private:
117  std::unique_ptr<IDataSourceStream> stream = nullptr;
118  HttpHeaders headers;
120 };
121 
File stream class.
Definition: FileStream.h:21
Encapsulates a set of HTTP header information.
Definition: HttpHeaders.h:35
Base class for read-only stream.
Definition: DataSourceStream.h:46
Definition: MailMessage.h:32
HttpHeaders & getHeaders()
Get a reference to the current set of headers.
String subject
Definition: MailMessage.h:38
MailMessage & addAttachment(IDataSourceStream *stream, const String &mime, const String &filename="")
Adds attachment to the email.
MailMessage & addAttachment(IDataSourceStream *stream, MimeType mime, const String &filename="")
Adds attachment to the email.
MailMessage & setHeader(const String &name, const String &value)
Set a header value.
Definition: MailMessage.h:55
MailMessage & setBody(const String &body, MimeType mime=MIME_TEXT)
Sets the body of the email.
MailMessage & addAttachment(FileStream *stream)
Adds attachment to the email.
String cc
Definition: MailMessage.h:39
~MailMessage()
Definition: MailMessage.h:41
MailMessage & setBody(String &&body, MimeType mime=MIME_TEXT) noexcept
Sets the body of the email using move semantics.
String to
Definition: MailMessage.h:36
String from
Definition: MailMessage.h:37
MailMessage & setBody(IDataSourceStream *stream, MimeType mime=MIME_TEXT)
Sets the body of the email.
Definition: SmtpClient.h:91
The String class.
Definition: WString.h:133
IDataSourceStream * stream
The currently active stream being sent.
Definition: TcpClient.h:165
MimeType
Definition: WebConstants.h:53