sipxtacklib  Version 3.3
MailMessage.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 //Example:
12 /*
13 
14  MailMessage message("XXX",
15  "XXX@pingtel.com",
16  "XXX.pingtel.com");
17  message.Body("this is a test message");
18  message.Subject("Hello World!");
19  message.To("XXX","XXX@pingtel.com");
20  message.Send();
21 
22 
23 */
24 
25 
26 // MailMessage class declaration for Mailer
27 
28 #ifndef __MAILMESSAGE_H__
29 #define __MAILMESSAGE_H__
30 
31 #include "os/OsDefs.h"
32 #include "MailAttachment.h"
33 
34 #include <vector>
35 using namespace std;
36 
38 {
39 public:
40  MailMessage(const UtlString &rFromName,
41  const UtlString &rFromAddress,
42  const UtlString &rSmtpServer)
43  {
44  UtlString fromName = rFromName.data();
45  m_From.Name = fromName.data();
46  UtlString fromAddress = rFromAddress.data();
47  m_From.Address = fromAddress;
48  UtlString smtpServer = rSmtpServer.data();
49  m_Server = smtpServer;
50  }
51 
52  void To(const UtlString &rName, const UtlString &rAddress)
53  {
54  UtlString name = rName.data();
55  UtlString address = rAddress.data();
56  m_vecTo.push_back(MailAddress(name,address));
57  }
58 
59  void Cc(const UtlString &rName, const UtlString &rAddress)
60  {
61  UtlString name = rName.data();
62  UtlString address = rAddress.data();
63  m_vecCc.push_back(MailAddress(name,address));
64  }
65 
66  void Bcc(const UtlString &rName, const UtlString &rAddress)
67  {
68  UtlString name = rName.data();
69  UtlString address = rAddress.data();
70  m_vecBcc.push_back(MailAddress(name,address));
71  }
72 
73  void Subject(const UtlString &rSubject)
74  {
75  UtlString subject = rSubject.data();
76  m_Subject = subject;
77  }
78 
79  void Body(const UtlString &rText);
80 
81  void Body(const UtlString &rText, const UtlString &rHtml);
82 
83  bool Attach(const UtlString &rFilename);
84 
85  bool Attach(const unsigned char *data, const int& rDatalength, const UtlString &rFilename );
86 
87  // Send the message to the SMTP server specified in the constructor.
88  // Return either "" or an error message.
89  UtlString Send();
90 
91 private:
92  UtlString FormatForSending();
93 
94  struct MailAddress
95  {
96  MailAddress() {;}
97  MailAddress(const UtlString &name, const UtlString &address)
98  { Name=name; Address=address; }
99  UtlString toString() const
100  {
101  UtlString str = "\"";
102  str += Name;
103  str += "\" <";
104  str += Address;
105  str += ">";
106  return str;
107  }
108  UtlString Name;
109  UtlString Address;
110  };
111 
112  MailAddress m_From;
113  vector<MailAddress> m_vecTo;
114  vector<MailAddress> m_vecCc;
115  vector<MailAddress> m_vecBcc;
116  UtlString m_Subject;
117  UtlString m_ContentType;
118  UtlString m_Body;
119  vector<MailAttachment> m_vecAttachment;
120  UtlString m_Server;
121 };
122 
123 #endif
void Subject(const UtlString &rSubject)
Definition: MailMessage.h:73
Definition: MailMessage.h:37
MailMessage(const UtlString &rFromName, const UtlString &rFromAddress, const UtlString &rSmtpServer)
Definition: MailMessage.h:40
void Bcc(const UtlString &rName, const UtlString &rAddress)
Definition: MailMessage.h:66
void To(const UtlString &rName, const UtlString &rAddress)
Definition: MailMessage.h:52
void Cc(const UtlString &rName, const UtlString &rAddress)
Definition: MailMessage.h:59

sipXtackLib home page