Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I need a sample C code to send emails

Status
Not open for further replies.

mhamini

Member level 1
Joined
Aug 23, 2005
Messages
40
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Iran-Tehran
Activity points
1,690
C code to send emails

Hi,
I would like to send emails on job status from an existing C prog but I'm not sure how. Can someone provide me with a sample code or direct me to a website?

Thanks.
 

Re: C code to send emails

I dont have any links to share but i can tell you the simple procedure that you need to follow. First install SMTP server. Then you need to use Socket programming in which you first establish a socket on the SMTP Server and then you can send series of commands like RCPT TO , MAIL FROM ,etc to SMTP server. Search more for "SMTP Commands" on google that might help you.
 

C code to send emails

**broken link removed**

There is an SMTP C library in LGPL
HTP
 

I'm also trying to send email via smtp, i would appreciate if someone could clear a few points for me :)
0. using telnet smtp.gmail.com 465, i get a connection, but i receive nothing from the server.. all the online tutorials i have read say i should receive some sort of 250 message when the connection is opened (i tried this with various servers and get the same response, i also tried port 25 in which case there's no connection)
1. if i ignore the fact that there's no welcome message and proceed to send a HELO command all that happens is that server just echos back whatever i send it.. there's no Ok message of any sort.

i have other questions but i guess i must get over these these two first!
please advice
regards
ryan
 

Re: C code to send emails

simplest way is just to run some command line mail client, like this one
**broken link removed**
i suppose question was about windows OS, so:

#include <process.h>
...
char cmdStr[MAX_STR_LENGTH];
sprintf_s(cmdStr, MAX_STR_LENGTH, "bmail.exe aaa bbb ccc", ...);
system(cmdStr);


or directly communicating with smtp server:
Win32 Command Line SMTP
 
Last edited:

Re: C code to send emails

simplest way is just to run some command line mail client, like this one
**broken link removed**
i suppose question was about windows OS, so:

#include <process.h>
...
char cmdStr[MAX_STR_LENGTH];
sprintf_s(cmdStr, MAX_STR_LENGTH, "bmail.exe aaa bbb ccc", ...);
system(cmdStr);


or directly communicating with smtp server:
Win32 Command Line SMTP

Thank you for your reply _pv
You're right it is for windows, I had actually already tried using bmail, it also fails to make a connection! I noticed I've made a mistake in the original post, what I meant to say was that when the connection is established I should recive a 220 message. The link you have sent me "win32 command line smtp" also specifies that this should happen. That's with agreement with every other online reference i have looked at. Unfortunatly the problem is that a 220 message never arrives!
Basically once the connection is opened there's absolute silence from the server, if i ignore the fact that 220 is never received and I send HELO message (just like adviced in all tutorials) all that happens is that the server echos whatever i send it. There's never any sort of intelligent reply, no Ok at all...

Any ideas what i'm missing? everywhere i have read confirms this.. if i type telnet smtp.gmail.com 25 i should receive a 220... but this never happens!!!
can someone please confirm this or let me know of an smtp server they know for certain to be working?
thanks
 

i have looked up many smtp lists online and none work, i believe these are becoming rare! better have a go at SSL and stick with gmail
cheers guys
 

How to send TLS or SSL through telnet ???

Wont it be good to set up a mail server on the LAN and send mail through that???

Earlier in 2005 I have developed a proxy server for SMTP for on e of my previous employer. We palnned to implement TLS and SSL but dropped it.

Next From the posts I guess the requirement is for an enterprise application. So what you can suggest the client to have "sendmail/PostFix" installed in the Network or on the machine where your application is installed. then add to your DNS server a MX record for the MAchine where you installed the mail server. now you are done.

Care should be taken that this machine should not be on the public Network, Or else You are inviting Problem for your self.;-)
 

if i do it through SSL i won't be using telnet, i'll do it in C. i was only using telnet to verify that it wasn't my program that was the problem, i.e. that there was an active and open smtp server on the other end.. unfortunately i found none
exactly, i rather not have to host my own mail sever and all the problems that come with it. besides, the whole point of this project was to get familiar with sockets etc
 

Well, I get a response, using the correct SMTP port 25
Code:
telnet smtp.gmail.com 25
 

virtually not possible, That is a security measure. Telnet doesn't support SSL/TLS
If you can program and use TLS from C Then you can communicate with the server.
I guess in C it is Doable.

But i have a question Why one want to access and use a server which doesn't belong to him/her?
Why not set-up a SMTP server locally? Postfix for lInux is free. Can create a VM and run minimal Linux and Postfix. that way 90% of the headache is gone. Is not it?

Well If the detail use case of the requirement is given then I can suggest some alternative on linux too:)
 

Well, I get a response, using the correct SMTP port 25
Code:
telnet smtp.gmail.com 25

well this means i'm doing something wrong then..

i connect to the internet through a belkin modem router, is there some sort of setup necessary? do i need to unblock port 25, or forward communications on port 25 to my laptop?
 

Don't know. You should get something like
220 mx.google.com ...
 

well this means i'm doing something wrong then..

i connect to the internet through a belkin modem router, is there some sort of setup necessary? do i need to unblock port 25, or forward communications on port 25 to my laptop?

Yes Sure. Until that port is free you cant send / receive any data. See if it is open.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top