|
Just reply to his message below
|
|
|
|
|
|
Have you tried downloading SSLEAY32.dll by searching for "Download SSLEAY32.dll". I think that generally this project is becoming more and more out of date. I think that cURL is kept up to date and has better promise. See libcurl example - smtp-tls.c[^]
|
|
|
|
|
ok thanks Eric
I'm going to try ...
|
|
|
|
|
|
Hi,
I tried to compil your project CodeProject-SMTPClientWithSSLorTLS with VS2017 and it's ok but when i launch the csmtp.exe i have this error
CSmtp.exe - Erreur système
---------------------------
Impossible d’exécuter le code, car SSLEAY32.dll est introuvable. La réinstallation du programme peut corriger ce problème.
Translation: The code could not be executed because SSLEAY32.dll was not found. Reinstalling the program may correct this problem.
---------------------------
OK
---------------------------
What can I do ?
thanks for your help
|
|
|
|
|
Hi David and John,
Could someone let me know how to submit the whole project. I made changes to:-
1. Make it work for 64 bit Windows and 32 bit Windows
2. Upgraded it to use openssl-1.0.2u (released in Dec 2019) instead of openssl-0.9.8l (released in Jan 2016)
I didn't want to upgrade the SLL library to the latest because it means having to use extra support DLLs. I personally prefer having it self contained.
There haven't been any updates for five years and I really need to submit the whole project but don't know how to do that. Could you let me know how to do that.
Thanks
Eric
|
|
|
|
|
I found that emails without the correct date/time format or time-zone were blocked by Spam Filters.
To fix it (for Windows), add the following declaration in void CSmtp::FormatHeader(char* header) in CSmtp.cpp:-
char dayofweek[][4] = {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
TIME_ZONE_INFORMATION TimeZoneInformation;
int success, timezonebias, houroffset, minuteoffset;
Then replace:-
snprintf(header, BUFFER_SIZE, "Date: %d %s %d %d:%d:%d\r\n", timeinfo->tm_mday,
month[timeinfo->tm_mon], timeinfo->tm_year+1900, timeinfo->tm_hour,
timeinfo->tm_min, timeinfo->tm_sec);
With:-
success = GetTimeZoneInformation(&TimeZoneInformation);
timezonebias = TimeZoneInformation.Bias;
if(timeinfo->tm_isdst) timezonebias += TimeZoneInformation.DaylightBias;
timezonebias = -timezonebias;
houroffset = timezonebias / 60;
minuteoffset = timezonebias % 60;
if(minuteoffset < 0) minuteoffset = -minuteoffset;
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);
|
|
|
|
|
I found that emails sent with attachments were blocked by Spam Filters if the attachment didn't have the correct mime type.
In this regard PDF attachements need to have the correct PDF mime type "Content-Type: application/pdf".
Only .exe and .dll attachments should have the mime type "Content-Type: application/x-msdownload".
In CSmtp.cpp, search for:-
strcat(SendBuf, "Content-Type: application/x-msdownload; name=\"");
strcat(SendBuf, EncodedFileName.c_str());
strcat(SendBuf, "\"\r\n");
And replace it with:-
// Use the correct mime-type
// see http://www.w3big.com/http/http-content-type.html
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(!_stricmp(LastFourCharsOfFileName, ".pdf"))
{
strcat(SendBuf, "Content-Type: application/pdf\r\n");
}
else if(!_stricmp(LastFourCharsOfFileName, ".exe") || !_stricmp(LastFourCharsOfFileName, ".dll"))
{
strcat(SendBuf, "Content-Type: application/x-msdownload; name=\"");
strcat(SendBuf, EncodedFileName.c_str());
strcat(SendBuf, "\"\r\n");
}
There are some issues with the above code:-
1. If the file extension is not .pdf, .exe or .dll then it doesn't use any mime type. I don't know
how spam filters will handle that.
2. I don't know if _stricmp works with Linux.
3. The file name is added with name=... I don't see that in the examples that I see online.
In my application we only send .pdf files so it doesn't matter.
|
|
|
|
|
Note that it is better to upgrade progressively (eg. to VS2015 then VS2019) rather than in one big step (in order for some defaults to come through correctly).
After upgrading the project to VS2015, VS2017 or VS2019:-
1. In Project Properties (for Debug), C/C++, All Options, Enable Minimal Build, Set to "No (/Gm-)"
2. In Project Properties (for Debug and Release), C/C++, Preprocessor, Add "_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;" (before %(PreprocessorDefinitions))
3. In Project Properties (for Debug and Release), Linker, Input, Additional Dependencies, Add "legacy_stdio_definitions.lib;" (before %(AdditionalDependencies))
4. In Project Properties (for Debug), Linker, Advanced, Image Has Safe Exception Handlers, Set to "No (/SAFESEH:NO)"
5. In main.cpp, after the two #defines at the top, add the following
extern "C" { FILE __iob_func[3] = {stdin,stdout,stderr}; }
6. In base64.cpp, replace "base64_chars.find" with "(unsigned char)base64_chars.find" in two places
7. In CSmtp.cpp, replace 'else recipient.Name.empty();' with 'else recipient.Name = "";' in three places
8. The project should now compile. If you are now getting a warning MSB4211, click View (menu at top), Other Windows, Property Manager, and delete "Upgrade from VC 6.0" (for Debug and Release)
see https:
And some tidy ups:
1. Delete the file CSmtp.vcproj (has been replaced with CSmtp.vcxproj)
2. Delete the file UpgradeLog.htm
3. In CSmtp.cpp, replace "http://www.codeproject.com" with "https://www.codeproject.com" (add the s to http)
4. In CSmtp.cpp, place a comment at the top "// Obtained from https://www.codeproject.com/Articles/98355/SMTP-Client-with-SSL-TLS" because the first three codeproject links are all dead links.
In my opinion, this project needs to be further upgraded by:-
1. Replacing legacy code with modern code (to get rid of _CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS; legacy_stdio_definitions.lib)
2. Converting it to 64 bit. The biggest issue will be getting the 64 bit versions of libeay32.lib and ssleay32.lib. Instructions on compiling a 64 bit version are at https:
3. Upgrade from openssl-0.9.8l to openssl-1.1.1. One disadvantage of upgrading the SSL library is that four support DLLs would now be required (two for 32 bit and two for 64 bit).
modified 28-Feb-21 17:45pm.
|
|
|
|
|
With Gmail (or Google Workspace) it is important to turn on "Access for less secure apps" otherwise you will get "Bad login or password". And to turn on "Access for less secure apps" you need to make sure that “2-Step Verification” is turned OFF.
For more information see SMTP Configuration[^]
|
|
|
|
|
I am getting an error while trying to include it in the additional dependencies section.
What static library do we have to include in the project
|
|
|
|
|
I used the latest version of the program, but when I sent it, I was prompted that I didn't set the address of the recipient. I have already set it. Undefined at least one receipent exception prompt is this. Why do I have this problem? Because of QQ email?
|
|
|
|
|
So I downloaded this code to help me with a project I am working on. I am using a software called putty to log me in to my schools server and use their c++. I transferred the files all except the visual studio ones and just as I was about to test it I get a message that says that CSmtp.h:26:26: fatal error: openssl/ssl.h: No such file or directory
#include <openssl ssl.h="">
I moved the files around, tried making it a direct path (like having it openssl-0.9.8l/inc32/openssl/ssl.h) and tried having just the ssl.h file be in the same directory as the CSmtp.h file but nothing works. Can someone try to help me with this issue? I really want to see if this thing can work but I can't get past the compiling stage and that is literally the only issue so far.
|
|
|
|
|
Is the timezone header missing? Since it is mentionend in the comment.
snprintf(header, BUFFER_SIZE, "Date: %d %s %d %d:%d:%d\r\n", timeinfo->tm_mday,
month[timeinfo->tm_mon], timeinfo->tm_year+1900, timeinfo->tm_hour,
timeinfo->tm_min, timeinfo->tm_sec);
Regards
|
|
|
|
|
I would suggest the following:
strftime(header, 80, "Date: %a, %d %b %Y %H:%M:%S %z (%Z)\r\n", timeinfo);
|
|
|
|
|
I can't find the SHA1 of CSmtp_v2_4_ssl.zip anywhere, does this file CSmtp_v2_4_ssl.zip have SHA1?
|
|
|
|
|
libeay32.lib(cryptlib.obj) : error LNK2001: 无法解析的外部符号 __imp__GetUserObjectInformationW@20
libeay32.lib(cryptlib.obj) : error LNK2001: 无法解析的外部符号 __imp__GetProcessWindowStation@0
libeay32.lib(cryptlib.obj) : error LNK2001: 无法解析的外部符号 __imp__GetDesktopWindow@0
libeay32.lib(cryptlib.obj) : error LNK2001: 无法解析的外部符号 __imp__MessageBoxA@16
libeay32.lib(cryptlib.obj) : error LNK2001: 无法解析的外部符号 __imp__DeregisterEventSource@4
libeay32.lib(cryptlib.obj) : error LNK2001: 无法解析的外部符号 __imp__ReportEventA@36
libeay32.lib(cryptlib.obj) : error LNK2001: 无法解析的外部符号 __imp__RegisterEventSourceA@8
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__DeleteDC@4
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__DeleteObject@4
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__GetBitmapBits@12
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__BitBlt@36
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__GetObjectA@12
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__SelectObject@8
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__CreateCompatibleBitmap@12
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__GetDeviceCaps@8
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__CreateCompatibleDC@4
libeay32.lib(rand_win.obj) : error LNK2001: 无法解析的外部符号 __imp__CreateDCA@16
what has this lib done? such like GetDesktopWindow(),i confused!
|
|
|
|
|
Hello David and John, You have a very nice project, thank you for the example. As you may already know, the encryption/decryption needs to be updated to support the more advanced versions in the newer Openssl versions. I tried using version 1.0.2l, and it fails in the call to CSmtp::OpenSSLConnect(). I would love to have your help figuring this out. Thanks again for the code example. Regards, Tom.
|
|
|
|
|
Hello,
example:
mail.AddMsgLine(".dt");
Only 'dt' is included to the email.
How to fix this bug, please help me.
Thank you.
|
|
|
|
|
Hello
I have download your code and compiled it in VS 2015
But these errors appeared.
LNK2019 unresolved external symbol _vsnprintf referenced in function _OPENSSL_showfatal
LNK2019 unresolved external symbol _vfprintf referenced in function _OPENSSL_showfatal
LNK2019 unresolved external symbol _iob_func referenced in function _OPENSSL_showfatal
LNK2001 unresolved external symbol _iob_func
LNK2001 unresolved external symbol _iob_func
LNK2001 unresolved external symbol _iob_func
LNK2019 unresolved external symbol _sscanf referenced in function _ipv4_from_asc
I dont know what the reason is.
I hope you can help me.
Thank you
|
|
|
|
|
This seems to be a disconnect between versions of openssl. The library is currently setup to use openssl-0.9.8l.
|
|
|
|
|
I had the same problems with vs2017 and platform v141. You can set platform to v100.
I didn't want to do that for my usage so I fixed it by:
add legacy_stdio_definitions.lib to the link section of the settings. That gets rid of the _vsnprintf errors.
For __iob_func error I added this too any .cpp file:
<pre>extern "C" FILE* __cdecl __iob_func(void)
{
FILE _iob[] = { *stdin, *stdout, *stderr };
return _iob;
}
Alternatively getting the source to openssl and recompiling with new settings would also fix it.
|
|
|
|
|
I'm tearing my hair out here and it's probably something really stupid that I'm doing (or not doing). I have downloaded version 2.2 (Looking at the changes up to 2.4 I don't think they address my problem). I then built my own console app to test it and, of course, added the appropriate paths for the SSL code. Built it and run it and it all works fine. Lovely!
I then added the code into my existing MFC application and once again added the appropriate paths for the SSL code. This time when I run it sits for several minutes on this line in InitOpenSSL():
m_ctx = SSL_CTX_new (SSLv23_client_method());
However when eventually it returns it doesn't immediately generate an error but goes on to the
OpenSSLConnect() function and from there it throws the
SSL_PROBLEM exception.
The calling code is identical (I literally commented out my original code and replaced it with the same test code from the demo program (which worked fine) so I can only assume there is something I've not done correctly in the project settings but I have compared the two sets of project settings and the only significant difference appears to be the fact that it is using MFC.
I would add that if I switch to using TLS it still hangs on the same line in InitOpenSSL() but then goes on to send the email successfully. And also that in the console app version it sends successfully for both SSL and TLS with no time spent hanging in that function.
I am most perplexed and would appreciate any help anyone can give!
Thanks
Mike
modified 24-May-17 9:09am.
|
|
|
|
|
I've come up with a couple of other bits of information on this now.
1. It works just fine in a SIMPLE MFC dialog box app.
2. It's still not working correctly in my full (quite large) program but I have noticed that when I first try to send an email it fails with the SSL problem message. However if I then send another email (without closing the program) it works fine and successfully sends the email. And that second email has no delay in the InitOpenSSL() function as there is on the first call.
So the InitOpenSSL() function takes a couple of minutes on it's first call. If it's TLS it then carries on and works, if it's SSL it fails on the first email but works thereafter.
All very curious!
Mike
|
|
|
|
|