|
I am using CSmtp Client with SSL/TLS .. Version 2.4 which was last revised on 22-Oct-2015
I tried configuring my Gmail Account using: smtp.gmail.com , 465 (SSL)
and also with smtp.gmail.com, 587 (TLS)
I also tried my company email id which is registered on yahoo
using smtp.bizmail.yahoo.com , 465 (SSL)
I am currently using my company email id on outlook without any issue.
But with this code, I am getting the error: Bad login or password
One thing, I check settings for both the accounts, they said . (Use Authentication: Yes)
and i enable it while configuring my Outlook. But i don't see option like this with this code. Or is it by default: enabled???
Looking for any help
Thanks in advance
Deepak Madan
|
|
|
|
|
Did you set m_bAuthenticate=true ?
|
|
|
|
|
Cross-compilation openssl, then on the board to run the program, there will be a print as follows:
"3069383764:error:14098077:SSL routines:SSL3_SEND_CLIENT_KEY_EXCHANGE:bad rsa encrypt:s3_clnt.c:2287:",
positioning:res = SSL_connect(m_ssl);CSmtp.cpp line:2399
But no such problem on x86.I don't know what reason be?
|
|
|
|
|
I'm not sure. It looks to be an issue between the library and OpenSSL. If you find a solution, post back.
|
|
|
|
|
|
I believe this:
if(name!=NULL) recipient.Name = name;
else recipient.Name.empty();
should be:
if(name!=NULL) recipient.Name = name;
else recipient.Name.clear();
empty() just tests the string, it doesn't clear it, like clear() does.
|
|
|
|
|
Great catch! I've fixed it for the next release of the code. Note that this needs to be fixed in three places: once for AddRecipient , once for AddCCRecipient and once for AddBCCRecipient .
Thanks,
David
|
|
|
|
|
I ported this code for use within an Unreal Engine 4 game - works great. Thanks for all the hard work.
Unfortunately I ran into heap corruption issues which I used Application Verifier to trace to line 1296 in CSMTP.cpp:
localtime_s(timeinfo, &rawtime);
It was trying to write a full 16 bytes past the end of the memory allocated a few lines earlier in:
struct tm *timeinfo;
timeinfo = (tm*)calloc(sizeof *timeinfo, 0);
So, since int seems to be a different size within the UE4 environment (I'm not 100%, but because its forcing x64 everywhere?), I had to explicitly use the size of int to allocate the space:
timeinfo = (tm*)calloc(sizeof *timeinfo, sizeof(int));
I'm not sure if this is allocating more than I need since I'm really new to self-managed dynamic memory allocation, but seems that its working for me. Hopefully this will either help someone else, or allow the wonderful devs to patch a potential bug.
Or maybe you guys can knock me on the head and tell me what I'm doing wrong.
Thanks,
Cameron
|
|
|
|
|
Cameron,
I'm not sure which version of the code you are using, but the current version does not have any calloc statements at all. Is this something you added?
Thanks,
David
|
|
|
|
|
CSmtp::ConnectRemoteServer never returns false in case of connection failure. It raises ECSmtp exception instead. I guess this is due to a bug at line 1216:
throw;
return false;
|
|
|
|
|
Got this working great using Visual Studio 2010. But Gmail requires account reduced security setting in order to accept login. Another option, according to Google, is to use enhanced security library. What libraries or enhancements of security for OpenSSL are available? Apparently OpenSSL has many security flaws. Any suggestions greatly appreciated.
|
|
|
|
|
Where is this reduced security setting in gmail? I don't remember having to set that to get it to work for me.
|
|
|
|
|
4 unresolved externals
_sscanf referenced in function _ipv4 from _asc
_vfprintf referenced in function _OPENSSL_showfatal
__vsnprintf referenced in function -OPENSSL_showfatal
__iob_func
__iob_func referenced in function _OPENSSL_showfatal
all in Project CSmtp having to do with libeay32.lib(v3_utl.obj),
libeay32.lib(cryptlib.obj) (rsa.sign.obj) (pm_lib.obj) (u_openssl.obj)
Any more recent fixes or updates for 2015?
Noted post below:
The error is because you have to link libeay32.lib and ssleay32.lib in linker->additional
Indeed, if you use vs 2013 its fine, these error are only in vs 2015
I'll give this a try.
|
|
|
|
|
You need to compile the two libs (ssleay32.lib and libeay32.lib) with your Visual Studio 2015 and then it will work.
Hope that helps,
|
|
|
|
|
could you elaborate what you mean by compile the two libraries? Where do I find the source code for these libraries?
I've never compiled a third party library for which I don't have the source before, so forgive me if I don't follow you.
|
|
|
|
|
You need to download openSSL from openssl.org.
|
|
|
|
|
Could the problem be that you compiled OpenSSL in VS2013 and are trying to compile the library in VS2015?
|
|
|
|
|
The "application/x-msdownload" mime type should only be used for .exe and .dll attachments!
I replaced the following lines:-
strcat(SendBuf, "Content-Type: application/x-msdownload; name=\"");
strcat(SendBuf, EncodedFileName.c_str());
strcat(SendBuf, "\"\r\n");
with the following:
const char *LastFourCharsOfFileName = FileName.c_str() + strlen(FileName.c_str()) - 4;
if(strlen(FileName.c_str()) < 4) {
// Very short filename which can't have a three letter extension, so do nothing
} else if(!strcmp(LastFourCharsOfFileName, ".pdf")) {
strcat(SendBuf, "Content-Type: application/pdf\r\n"); // See http://pdf.mime-application.com/ and http://stackoverflow.com/questions/312230/proper-mime-media-type-for-pdf-files
} else if(!strcmp(LastFourCharsOfFileName, ".exe") || !strcmp(LastFourCharsOfFileName, ".dll")) {
strcat(SendBuf, "Content-Type: application/x-msdownload; name=\""); // See http://x-msdownload.mime-application.com/
strcat(SendBuf, EncodedFileName.c_str());
strcat(SendBuf, "\"\r\n");
}
That makes it work correctly for PDF, EXE and DLL attachments. Don't know about other ones?
Eric
Eric
|
|
|
|
|
Eric,
Per RFC 1341:
An "application" Content-Type value, which can be used to transmit application data or binary data, and hence, among other uses, to implement an electronic mail file transfer service.
As I understand it, it is intended to signify any type of binary data. Do you have a source that sites a different set of requirements?
|
|
|
|
|
After making the date change suggested by Eric Schwerzel and adding a function to allow for setting the m_bHTML boolean, it's working well.
Thanks for sharing!
John
|
|
|
|
|
error:Server returned error after sending EHLO
why?
|
|
|
|
|
Most likely its the combination of port and security settings you are using.
|
|
|
|
|
Great code!
It's not clear for me why if I put a message like:
mail.AddMsgLine("How are you today?123456789/-+èé+*çò°à@#§ù-_<>ì^|()[]{}");
I recieve in the email:
How are you today?123456789/-+鴇+*趛啤@#杜-_<>餧|()[]{}
There is some convertion to do to get the correct string without strange symbols??
Thanks
|
|
|
|
|
I'm not sure. Please post back if you find a solution.
Thanks,
David
|
|
|
|
|
There is a bug with how the date is formatted which I've been told is getting the emails sent being marked as Spam. If the email is sent at one second and one minute past one, the date generated is:
Date: 1 Jan 2016 1:1:1
when it should be
Date: 01 Jan 2016 01:01:01
The date, hours, minutes and seconds need to be two digits each (see http://email.about.com/od/Email-Standards-Tips/qt/How-To-Understand-Date-And-Time-In-Email-Headers.htm), so you need to replace:
snprintf(header, BUFFER_SIZE, "Date: %d %s %d %d:%d:%d\r\n", timeinfo->tm_mday,
with:
snprintf(header, BUFFER_SIZE, "Date: %02d %s %04d %02d:%02d:%02d\r\n", timeinfo->tm_mday,
If you also want the day of the week and correct timezone to be displayed (recommended to make the spam filters happier) then you can have the following for the first part of FormatHeader (the #### are where all the changes are):-
void CSmtp::FormatHeader(char* header)
{
char month[][4] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
char dayofweek[][4] = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}; // ####
TIME_ZONE_INFORMATION TimeZoneInformation; // ####
int success, timezonebias, houroffset, minuteoffset; // ####
size_t i;
std::string to;
std::string cc;
std::string bcc;
time_t rawtime;
struct tm* timeinfo;
// date/time check
if(time(&rawtime) > 0)
timeinfo = localtime(&rawtime);
else
throw ECSmtp(ECSmtp::TIME_ERROR);
// check for at least one recipient
if(Recipients.size())
{
for (i=0;i<Recipients.size();i++)
{
if(i > 0)
to.append(",");
to += Recipients[i].Name;
to.append("<");
to += Recipients[i].Mail;
to.append(">");
}
}
else
throw ECSmtp(ECSmtp::UNDEF_RECIPIENTS);
if(CCRecipients.size())
{
for (i=0;i<CCRecipients.size();i++)
{
if(i > 0)
cc. append(",");
cc += CCRecipients[i].Name;
cc.append("<");
cc += CCRecipients[i].Mail;
cc.append(">");
}
}
// Determine the Time Zone string. See http://email.about.com/od/Email-Standards-Tips/qt/How-To-Understand-Date-And-Time-In-Email-Headers.htm ####
success = GetTimeZoneInformation(&TimeZoneInformation); // This is a Windows function call - don't know how to make this portable?
timezonebias = TimeZoneInformation.Bias; // Normal timezone
if(timeinfo->tm_isdst) timezonebias += TimeZoneInformation.DaylightBias; // Timezone adjusted for daylight saving
timezonebias = -timezonebias; // In the email headers it is the negative of the Windows value
houroffset = timezonebias / 60; // Truncate towards zero
minuteoffset = timezonebias % 60; // Modulus (remainder of minutes)
if(minuteoffset < 0) minuteoffset = -minuteoffset; // Only use the negative sign once (don't allow negative minutes)
// Date: <SP> <day of week>, <dd> <SP> <mon> <SP> <yy> <SP> <hh> ":" <mm> ":" <ss> <SP> <timezone> <CRLF> // ####
snprintf(header, BUFFER_SIZE, "Date: %s, %02d %s %04d %02d:%02d:%02d %+02d%02d\r\n", dayofweek[timeinfo->tm_wday], timeinfo->tm_mday, // ####
month[timeinfo->tm_mon], timeinfo->tm_year+1900, timeinfo->tm_hour,
timeinfo->tm_min, timeinfo->tm_sec, houroffset, minuteoffset); // ####
// From: <SP> <sender> <SP> "<" <sender-email> ">" <CRLF>
if(!m_sMailFrom.size()) throw ECSmtp(ECSmtp::UNDEF_MAIL_FROM);
... etc
Eric Schwerzel
|
|
|
|
|