smtp-client
SMTP Client C Library
SMTPMail.cpp
Go to the documentation of this file.
1 
11 #include "SMTPMail.h"
12 
14  this->status_code = status_code;
15 }
16 
17 const char *const
20 }
21 
23 }
24 
26 }
27 
28 void SMTPMail::open(const char *const server,
29  const char *const port,
30  enum smtp_connection_security connection_security,
31  enum smtp_flag flags,
32  const char *const cafile){
33  this->rc = smtp_open(server,
34  port,
35  connection_security,
36  flags,
37  cafile,
38  &this->smtp);
39  this->throw_bad_status_code();
40 }
41 
43  const char *const user,
44  const char *const pass){
45  this->rc = smtp_auth(this->smtp, auth_method, user, pass);
46  this->throw_bad_status_code();
47 }
48 
49 void SMTPMail::mail(const char *const body){
50  this->rc = smtp_mail(this->smtp, body);
51  this->throw_bad_status_code();
52 }
53 
54 void SMTPMail::close(void){
55  this->rc = smtp_close(this->smtp);
56  this->throw_bad_status_code();
57 }
58 
60  return smtp_status_code_get(this->smtp);
61 }
62 
63 void SMTPMail::status_code_set(enum smtp_status_code new_status_code){
64  this->rc = smtp_status_code_set(this->smtp, new_status_code);
65  this->throw_bad_status_code();
66 }
67 
68 void SMTPMail::header_add(const char *const key,
69  const char *const value){
70  this->rc = smtp_header_add(this->smtp, key, value);
71  this->throw_bad_status_code();
72 }
73 
76 }
77 
79  const char *const email,
80  const char *const name){
81  this->rc = smtp_address_add(this->smtp, type, email, name);
82  this->throw_bad_status_code();
83 }
84 
87 }
88 
89 void SMTPMail::attachment_add_path(const char *const name,
90  const char *const path){
91  this->rc = smtp_attachment_add_path(this->smtp, name, path);
92  this->throw_bad_status_code();
93 }
94 
95 void SMTPMail::attachment_add_fp(const char *const name,
96  FILE *fp){
97  this->rc = smtp_attachment_add_fp(this->smtp, name, fp);
98  this->throw_bad_status_code();
99 }
100 
101 void SMTPMail::attachment_add_mem(const char *const name,
102  const void *const data,
103  ssize_t datasz){
104  this->rc = smtp_attachment_add_mem(this->smtp, name, data, datasz);
105  this->throw_bad_status_code();
106 }
107 
110 }
111 
113  if(this->rc != SMTP_STATUS_OK){
114  throw SMTPMailException(this->rc);
115  }
116 }
117 
enum smtp_status_code smtp_close(struct smtp *smtp)
Definition: smtp.c:3168
const char * smtp_status_code_errstr(enum smtp_status_code status_code)
Definition: smtp.c:3241
enum smtp_status_code smtp_status_code_set(struct smtp *const smtp, enum smtp_status_code new_status_code)
Definition: smtp.c:3231
enum smtp_status_code smtp_attachment_add_mem(struct smtp *const smtp, const char *const name, const void *const data, size_t datasz)
Definition: smtp.c:3462
void attachment_add_fp(const char *const name, FILE *fp)
Definition: SMTPMail.cpp:95
void address_clear_all(void)
Definition: SMTPMail.cpp:85
enum smtp_status_code smtp_header_add(struct smtp *const smtp, const char *const key, const char *const value)
Definition: smtp.c:3278
void auth(enum smtp_authentication_method auth_method, const char *const user, const char *const pass)
Definition: SMTPMail.cpp:42
enum smtp_status_code smtp_mail(struct smtp *const smtp, const char *const body)
Definition: smtp.c:3062
~SMTPMail(void)
Definition: SMTPMail.cpp:25
enum smtp_status_code smtp_attachment_add_path(struct smtp *const smtp, const char *const name, const char *const path)
Definition: smtp.c:3416
void smtp_attachment_clear_all(struct smtp *const smtp)
Definition: smtp.c:3515
void attachment_add_path(const char *const name, const char *const path)
Definition: SMTPMail.cpp:89
smtp_connection_security
Definition: smtp.h:140
void attachment_clear_all(void)
Definition: SMTPMail.cpp:108
SMTPMailException(enum smtp_status_code status_code)
Definition: SMTPMail.cpp:13
void attachment_add_mem(const char *const name, const void *const data, ssize_t datasz)
Definition: SMTPMail.cpp:101
void smtp_header_clear_all(struct smtp *const smtp)
Definition: smtp.c:3332
void address_add(enum smtp_address_type type, const char *const email, const char *const name)
Definition: SMTPMail.cpp:78
int status_code_get(void)
Definition: SMTPMail.cpp:59
void open(const char *const server, const char *const port, enum smtp_connection_security connection_security, enum smtp_flag flags, const char *const cafile)
Definition: SMTPMail.cpp:28
virtual const char *const what()
Definition: SMTPMail.cpp:18
SMTPMail(void)
Definition: SMTPMail.cpp:22
void smtp_address_clear_all(struct smtp *const smtp)
Definition: smtp.c:3401
smtp_status_code
Definition: smtp.h:32
smtp_authentication_method
Definition: smtp.h:170
enum smtp_status_code status_code
Definition: SMTPMail.h:45
enum smtp_status_code smtp_address_add(struct smtp *const smtp, enum smtp_address_type type, const char *const email, const char *const name)
Definition: smtp.c:3347
void status_code_set(enum smtp_status_code new_status_code)
Definition: SMTPMail.cpp:63
void mail(const char *const body)
Definition: SMTPMail.cpp:49
void close(void)
Definition: SMTPMail.cpp:54
void throw_bad_status_code(void)
Definition: SMTPMail.cpp:112
Definition: smtp.c:150
smtp_flag
Definition: smtp.h:198
enum smtp_status_code smtp_auth(struct smtp *const smtp, enum smtp_authentication_method auth_method, const char *const user, const char *const pass)
Definition: smtp.c:3026
enum smtp_status_code smtp_attachment_add_fp(struct smtp *const smtp, const char *const name, FILE *fp)
Definition: smtp.c:3439
enum smtp_status_code smtp_status_code_get(const struct smtp *const smtp)
Definition: smtp.c:3217
SMTPMail class wrapper for smtp-client library.
enum smtp_status_code smtp_open(const char *const server, const char *const port, enum smtp_connection_security connection_security, enum smtp_flag flags, const char *const cafile, struct smtp **smtp)
Definition: smtp.c:2987
void header_clear_all(void)
Definition: SMTPMail.cpp:74
smtp_address_type
Definition: smtp.h:105
void header_add(const char *const key, const char *const value)
Definition: SMTPMail.cpp:68