Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » SmtpMail class
SmtpMail class [message #5624] Fri, 06 October 2006 11:04 Go to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
Somebody has a tutorial or information about the SmtpMail class of the Package Web?

I had thought about using the classes defined in the jwSMTP library that I have found in sourceforge (http://johnwiggins.net/jwsmtp/) which they work fine and are easy to use.

Nevertheless I believe that the SmtpMail class can work better and is already integrated in U++, but is no type of documentation on how it is used.

Nico

[Updated on: Fri, 06 October 2006 11:04]

Report message to a moderator

Re: SmtpMail class [message #5627 is a reply to message #5624] Fri, 06 October 2006 13:56 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Fri, 06 October 2006 11:04

Somebody has a tutorial or information about the SmtpMail class of the Package Web?
...


I'm interested too in a minimalist example.
Thanks,

Luigi
Re: SmtpMail class [message #5636 is a reply to message #5627] Fri, 06 October 2006 18:37 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
I have throughout been studying this class the day and I believe that I have reached some conclusion.

The host that this class needs, is not like in other objects acceding to protocol smtp; with this class we directly sent the mail to the server of the mail recipient.

Then, the problem is in finding out which is the name of host for a given server, since if we sent a mail to alguien@gmail.com, host IS NOT gmail.com. I Think I need to find the MX record from gmail.com.

I have found some codes GNU useful, but finally I have remained with one found here
http://viewcvs.pointblue.com.pl/index.cgi/gj/sendemail/mx.c

I have written with it an example that I'm attached here, so that we pruned to follow the conversation between all.

Nico

PS. I don't know if the sample works in windows, because it use the (unknow for me) 'resolv' library
  • Attachment: test_smtp.zip
    (Size: 5.96KB, Downloaded 1917 times)
Re: SmtpMail class [message #5637 is a reply to message #5636] Fri, 06 October 2006 19:03 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Fri, 06 October 2006 18:37

I have throughout been studying this class the day and I believe that I have reached some conclusion.

The host that this class needs, is not like in other objects acceding to protocol smtp; with this class we directly sent the mail to the server of the mail recipient.

Then, the problem is in finding out which is the name of host for a given server, since if we sent a mail to alguien@gmail.com, host IS NOT gmail.com. I Think I need to find the MX record from gmail.com.

I have found some codes GNU useful, but finally I have remained with one found here
http://viewcvs.pointblue.com.pl/index.cgi/gj/sendemail/mx.c

I have written with it an example that I'm attached here, so that we pruned to follow the conversation between all.

Nico

PS. I don't know if the sample works in windows, because it use the (unknow for me) 'resolv' library



In fact doesn't work Confused
It stopped to
#include <netdb.h>
I try to get it

Luigi
Re: SmtpMail class [message #5684 is a reply to message #5637] Mon, 09 October 2006 20:13 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
Hey Luigi!
There are other version of test_smtp. It does not need to link to "resolv" because I have downloaded the library code from opensolaris ( https://cvs.opensolaris.org/source/xref/on/usr/src/lib/libre solv2/). May be work in windows?

The test program works ok in linux.


Nico

[Updated on: Mon, 09 October 2006 20:20]

Report message to a moderator

Re: SmtpMail class [message #5685 is a reply to message #5684] Mon, 09 October 2006 21:10 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Mon, 09 October 2006 20:13

Hey Luigi!
There are other version of test_smtp. It does not need to link to "resolv" because I have downloaded the library code from opensolaris ( https://cvs.opensolaris.org/source/xref/on/usr/src/lib/libre solv2/). May be work in windows?

The test program works ok in linux.

Nico


Ciao Nico,

I have added in c_sinonyms.h
#include <Core/Core.h>
to indicate where to find the unistd.h include, but I got the error:
" RTTI must be enabled !!! "
coming from Core.h file.
I do not know what it is.

Luigi
Re: SmtpMail class [message #5686 is a reply to message #5685] Mon, 09 October 2006 21:17 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
The problem may be that the files in folder "resolv" is in normal (or old) C, and the includes <Core/Core.h> is a C++ files. The linkage and compile mode is very much diferent.

See the declaration of get_mail_server function
extern "C" const char *get_mail_server( const char *remote );


I believe that the RTTI cannot be qualified if we compiled in pure C.

But, what is and why you need unistd.h?

Nico
Re: SmtpMail class [message #5687 is a reply to message #5686] Mon, 09 October 2006 21:30 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Mon, 09 October 2006 21:17


But, what is and why you need unistd.h?

Nico


It is needed for some obscure reason by c_sinonyms.h.
Perhaps we should have a look to jwSMTP .

Luigi

[Updated on: Mon, 09 October 2006 21:32]

Report message to a moderator

Re: SmtpMail class [message #5694 is a reply to message #5687] Tue, 10 October 2006 10:30 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
oooops!
I'm sorry. c_sinonyms.h. file is in csv repository of opensolaris an "empty" file. The content is writen for my and is the result of copy-paste from an example ...¿?

That file 'unistd.h' is not necessary, at least in linux. You can comment or delete the line.

Nico

[Updated on: Tue, 10 October 2006 10:31]

Report message to a moderator

Re: SmtpMail class [message #5698 is a reply to message #5694] Tue, 10 October 2006 15:25 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Tue, 10 October 2006 10:30

oooops!
I'm sorry. c_sinonyms.h. file is in csv repository of opensolaris an "empty" file. The content is writen for my and is the result of copy-paste from an example ...¿?

That file 'unistd.h' is not necessary, at least in linux. You can comment or delete the line.

Nico



I've commented 'unistd.h', but now the compiler complain about
#include <sys/un.h>
that is absent in my 610-dev1.
Have you any new idea?

Luigi
Re: SmtpMail class [message #5700 is a reply to message #5698] Tue, 10 October 2006 16:06 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
Crying or Very Sad The truth is that I do not have nor idea of how causing that this works in Windows. I'm tried and I have your same problem.

I'm writing a program towards which to be able to send customized email to many directions.

Initially I thought about using classes GPL of jwSMTP that there is in sourceforge (my program will be GPL). I have proven them and work well in Windows and Linux.

We could watch the code of those classes and to see how it works I believe that it is a heavy work. Confused

Nico
Re: SmtpMail class [message #5704 is a reply to message #5700] Tue, 10 October 2006 16:57 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Tue, 10 October 2006 16:06


We could watch the code of those classes and to see how it works I believe that it is a heavy work. Confused

Nico


Yes, I believe too (even because I've no experience in this field). In future I'll try jwsmtp.
Luigi
Re: SmtpMail class [message #5761 is a reply to message #5704] Fri, 13 October 2006 13:28 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
EOH Luigi!

I have looked for information about all this and have found documents (he is Spanish) that say to me that in Windows we need to include the file winsock.h has to use the unique include file.

Take a look to the next code present in Web/socket.h

#if defined(PLATFORM_WIN32)
#define W_P(w, p) w
#if !defined(PLATFORM_CYGWIN)
#include <winsock2.h>
#endif
typedef int socklen_t;
#elif defined(PLATFORM_POSIX)
#define W_P(w, p) p
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
//#include <libiberty.h>
enum
{
	INVALID_SOCKET = -1,
	TCP_NODELAY    = 1,
	SD_RECEIVE     = 0,
	SD_SEND        = 1,
	SD_BOTH        = 2,
};
typedef int SOCKET;
#else
#error Unsupported platform
#endif//PLATFORM switch


May be you can test it in windoz!

The idea comes from this page http://www.arrakis.es/~dmrq/beej/intro.html#windows.
In order to translate it of automatic form (it is not perfect, but enough aid) you could use the following address http://babelfish.altavista.com/tr

Nico
Re: SmtpMail class [message #5762 is a reply to message #5761] Fri, 13 October 2006 13:35 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
HELO!!!

The original English page is here http://beej.us/guide/bgnet/

Nico
Re: SmtpMail class [message #5766 is a reply to message #5762] Fri, 13 October 2006 21:40 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Fri, 13 October 2006 13:35

HELO!!!

The original English page is here http://beej.us/guide/bgnet/

Nico


Ciao Nico,

I tried to use that include but the error messages increased. In the next week I try the jwsmtp library.

Luigi
Re: SmtpMail class [message #5778 is a reply to message #5766] Sun, 15 October 2006 23:13 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
Hello Luigi

This weekend I have investigated a little plus the subject this of the SmtpMail class and have for of conclusions that I believe that they are important.

In Linux I can use the class to directly send mail to the adressees (using the resolv library) who we could make an effort to us in port to Windows... but arises the problem from which if we used this method, then the servers think that the machine that sends the mail it have a virus of which they send Spam and they mark the IP like spamer.

At sight of this problem I see clear that we will not be able to use this method in the future (and in Windows either in the present) so I have myself I decide to use the classic method of mail shipment, that is to say, happening through a real smtp server.

This enough difficult me the management of the send-errors in my program, but the mails arrive at least at their destiny.

For it I have as much been using the class jwSMTP that works very well, in linux and Windows, but it has the problem of which the license is GPL. Well, for my it is not problem, but it would prefer to use a class better integrated in U++.

The case is that I have extracted of the class jwSMTP the code that serves to autentificate (to do login) in smtp server, I have added it class to the SmtpMail and.... it works!

I have created a class new "SmtpMailEx" to test here and you the shipment so that you prove it in Windows to see what happens.

If this works, I believe that we could propose to Mirek to add these functions to the original class, and of step to put the messages that are in cheko in English or to use the method of standard translation.

In any case you have the class here.

Nico
  • Attachment: smtpEx.zip
    (Size: 4.75KB, Downloaded 1949 times)
Re: SmtpMail class [message #5780 is a reply to message #5778] Mon, 16 October 2006 00:27 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Sun, 15 October 2006 23:13

Hello Luigi

This weekend I have investigated a little plus the subject this of the SmtpMail class and have for of conclusions that I believe that they are important.

In Linux I can use the class to directly send mail to the adressees (using the resolv library) who we could make an effort to us in port to Windows... but arises the problem from which if we used this method, then the servers think that the machine that sends the mail it have a virus of which they send Spam and they mark the IP like spamer.

At sight of this problem I see clear that we will not be able to use this method in the future (and in Windows either in the present) so I have myself I decide to use the classic method of mail shipment, that is to say, happening through a real smtp server.

This enough difficult me the management of the send-errors in my program, but the mails arrive at least at their destiny.

For it I have as much been using the class jwSMTP that works very well, in linux and Windows, but it has the problem of which the license is GPL. Well, for my it is not problem, but it would prefer to use a class better integrated in U++.

The case is that I have extracted of the class jwSMTP the code that serves to autentificate (to do login) in smtp server, I have added it class to the SmtpMail and.... it works!

I have created a class new "SmtpMailEx" to test here and you the shipment so that you prove it in Windows to see what happens.

If this works, I believe that we could propose to Mirek to add these functions to the original class, and of step to put the messages that are in cheko in English or to use the method of standard translation.

In any case you have the class here.

Nico


Ciao Nico!

Congratulation for your new achievement. Your news are very good.
Unfortunately I'm a bit confused. Your new class substitute the old one in the current U++ distribution?
Moreover, which test case have I to use to see this class in action?
You posted different versions and I do not knwo what to do.

Luigi
Re: SmtpMail class [message #5785 is a reply to message #5780] Mon, 16 October 2006 10:08 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
The class that I have added have the name: SmtpMailEx and is compatible with SmtpMail in Web package.

This a complete retort of the SmtpMail class to which I have added a function that makes the authentication in smtp server.

Also I have changed the size of the buffer of reading of socket (since it gave errors me).

In order to be able to prove simply you must it open new package, to include package Web and to add the 2 files that there are in zip which I raised yesterday. In order to prove it, simply you must copy the following code.
mail.Host("smtp.YOURSERVER.net")
	.From("FROM@SERVER.COM")
	.Subject("Jelou friend!")
	.To("TO@OTHER.COM")
	.Text("ANY TEXT\nBYE")
	.User("USER")
	.Password("PASSWORD") ;

	if (mail.Send())
		Cout() << "OK\r\n" ;
	else
		Cout() << "BAD\r\n" ;
	Cout() << mail.GetError() << "\r\n" 
	<< mail.GetTranscript() << "\r\n" ;

On the other hand, do not try to replace the original class, only I would like to see if it works in Windows to include the new functionalities in the original class.

Re: SmtpMail class [message #5796 is a reply to message #5785] Mon, 16 October 2006 15:23 Go to previous message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
nicomesas wrote on Mon, 16 October 2006 10:08

In order to be able to prove simply you must it open new package, to include package Web and to add the 2 files that there are in zip which I raised yesterday. In order to prove it, simply you must copy the following code.
mail.Host("smtp.YOURSERVER.net")
	.From("FROM@SERVER.COM")
	.Subject("Jelou friend!")
	.To("TO@OTHER.COM")
	.Text("ANY TEXT\nBYE")
	.User("USER")
	.Password("PASSWORD") ;

	if (mail.Send())
		Cout() << "OK\r\n" ;
	else
		Cout() << "BAD\r\n" ;
	Cout() << mail.GetError() << "\r\n" 
	<< mail.GetTranscript() << "\r\n" ;




Hola Nicoooo!

I'm happy to announce to the U++ community that your experiment is a total success. In fact the following code:
#include <Core/Core.h>
#include <Web/Web.h>
#include <winsock.h> 

bool sendMail(String to, String from)
{
  SmtpMailEx mail ;
	
  mail.Host("smtp.tele2.it")
	.From( from )
	.Subject("Jelou friend!")
	.To( to )
	.Text("ANY TEXT\nBYE")
//	.User("xxxxxx")      // I do not need autentication
//	.Password("xxxxx")
 ;

	if (mail.Send())
		Cout() << "OK\r\n" ;
	else
		Cout() << "BAD\r\n" ;
	Cout() << mail.GetError() << "\r\n" << mail.GetTranscript() << "\r\n" ;	
}


CONSOLE_APP_MAIN
{
	sendMail("forlano@fis.unical.it", "luigi.forlano@tin.it" ) ; 
	sendMail("luigi.forlano@tin.it" , "luigi.forlano@tin.it") ;
}

and your previous class smtpEx.cpp + smtpEx.h was able to send email! Just a note. The file Web.h need the inclusion of the line
#include "smtpEx.h"

Quote:

On the other hand, do not try to replace the original class, only I would like to see if it works in Windows to include the new functionalities in the original class.


I wish to see this fix in the official release of our lovely toolkit.

Luigi
Previous Topic: method in separate process
Next Topic: Socket: how to check wether new data arrived? timeout = NULL?
Goto Forum:
  


Current Time: Sun Apr 28 22:57:52 CEST 2024

Total time taken to generate the page: 0.04000 seconds