Electroneum
Loading...
Searching...
No Matches
smtp_helper.h
Go to the documentation of this file.
1// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above copyright
9// notice, this list of conditions and the following disclaimer in the
10// documentation and/or other materials provided with the distribution.
11// * Neither the name of the Andrey N. Sabelnikov nor the
12// names of its contributors may be used to endorse or promote products
13// derived from this software without specific prior written permission.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
19// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26
27
28
29
30#pragma once
31#include "smtp.h"
32
33namespace epee
34{
35namespace net_utils
36{
37 namespace smtp
38 {
39
40 inline bool send_mail(const std::string& server, int port, const std::string& login, const std::string& pass, const std::string& from_addres, const std::string& from_name, const std::string& maillist, const std::string& subject, const std::string& mail_body)
41 {
42 net_utils::smtp::CSMTPClient smtp;
43
44 if ( !smtp.ServerConnect( server.c_str(), port ) )
45 {
46 LOG_PRINT("Reporting: Failed to connect to server " << server <<":"<< port, LOG_LEVEL_0);
47 return false;
48 }
49
50 if(login.size() && pass.size())
51 {
52 if ( !smtp.ServerLogin( login.c_str(), pass.c_str()) )
53 {
54 LOG_PRINT("Reporting: Failed to auth on server " << server <<":"<< port, LOG_LEVEL_0);
55 return false;
56
57 }
58 }
59
60 if ( !smtp.SendMessage( from_addres.c_str(),
61 from_name.c_str(),
62 maillist.c_str(),
63 subject.c_str(),
64 "bicycle-client",
65 (LPBYTE)mail_body.data(),
66 mail_body.size()))
67 {
68 char *szErrorText = smtp.GetLastErrorText();
69 if ( szErrorText )
70 {
71 LOG_PRINT("Failed to send message, error text: " << szErrorText, LOG_LEVEL_0);
72 }
73 else
74 {
75 LOG_PRINT("Failed to send message, error text: null", LOG_LEVEL_0);
76 }
77 return false;
78 }
79
80 smtp.ServerDisconnect();
81
82 return true;
83
84
85 }
86 }
87}
88}
bool send_mail(const std::string &server, int port, const std::string &login, const std::string &pass, const std::string &from_email, const std::string &maillist, const std::string &subject, const std::string &body)
Definition smtp.h:166