Industry Online Support
Technical Forum
1/13/2009 8:47 AM | |
Posts: 8 Rating: (1) |
Dear All. I'm trying to send emails with alarm's information. I'm doing this with the function GMsgFunction and the sendmail.exe program, but it doesn't work because I can´t generate the body of my mails in program. Then I was looking for in web for generate my emails with C, for create one proyect's function and call this from GMsgFunction, and i find this: #include <winsock2.h> #include <windows.h> #include <iostream.h> #define MAX_LENGTH 1024 void main() { int s_len, r_len; int skt_Smtp; int success; struct sockaddr_in st_Sockaddr; char recv_Buf[MAX_LENGTH]; char send_Buf[MAX_LENGTH]; //Initialize Sockets WSADATA wsa; WSAStartup(MAKEWORD(2, 0), &wsa); skt_Smtp = socket(AF_INET,SOCK_STREAM,0); if (skt_Smtp < 0) { cout<< "Error Creating Socket"<<endl; return; } else { st_Sockaddr.sin_family = AF_INET; st_Sockaddr.sin_port = htons(25); //Get the IP address and initialize the structure st_Sockaddr.sin_addr.s_addr = inet_addr("IPAddress"); success = connect(skt_Smtp,(struct sockaddr *) &st_Sockaddr,sizeof(st_Sockaddr)); r_len = recv(skt_Smtp,recv_Buf,MAX_LENGTH,0); recv_Buf[r_len] = '\0'; cout<< recv_Buf<<endl; //Say Hello to the domain strcpy(send_Buf,"HELO sampledomain.com\r\n"); s_len = send(skt_Smtp,send_Buf,strlen(send_Buf),0); r_len = recv(skt_Smtp,recv_Buf,MAX_LENGTH,0); recv_Buf[r_len] = '\0'; cout<< recv_Buf<<endl; //Send from address strcpy(send_Buf , "MAIL FROM: frome-mailid@sampledomain.com\r\n"); s_len = send(skt_Smtp,send_Buf,strlen(send_Buf),0); r_len = recv(skt_Smtp,recv_Buf,MAX_LENGTH,0); recv_Buf[r_len] = '\0'; cout<< recv_Buf<<endl; //Send RCPT address strcpy(send_Buf,"RCPT TO:<toemail-id@sampledomain.com>\r\n"); s_len = send(skt_Smtp,send_Buf,strlen(send_Buf),0); r_len = recv(skt_Smtp,recv_Buf,MAX_LENGTH,0); recv_Buf[r_len] = '\0'; cout<< recv_Buf<<endl; // Send DATA strcpy(send_Buf,"DATA\r\n"); s_len = send(skt_Smtp,send_Buf,strlen(send_Buf),0); r_len = recv(skt_Smtp,recv_Buf,MAX_LENGTH,0); recv_Buf[r_len] = '\0'; cout<< recv_Buf<<endl; // Send DATA strcpy(send_Buf,"Subject:Test Win32 command line SMTP Subject\r\n\r\n"); s_len = send(skt_Smtp,send_Buf,strlen(send_Buf),0); //Send body strcpy(send_Buf,"Test e-mail for Win32 command line SMTP\r\n.\r\n"); s_len = send(skt_Smtp,send_Buf,strlen(send_Buf),0); r_len = recv(skt_Smtp,recv_Buf,MAX_LENGTH,0); recv_Buf[r_len] = '\0'; cout<< recv_Buf<<endl; //Send QUIT strcpy(send_Buf,"QUIT\n"); s_len = send(skt_Smtp,send_Buf,strlen(send_Buf),0); r_len = recv(skt_Smtp,recv_Buf,MAX_LENGTH,0); recv_Buf[r_len] = '\0'; cout<< recv_Buf<<endl; closesocket(skt_Smtp); } WSACleanup(); } but to compiling can´t find: #include <winsock2.h> #include <windows.h> #include <iostream.h> Someone Idea??? Tnx |
Last edited by: T.O at: 1/13/2009 8:48 AM |
|
1/14/2009 8:51 PM | |
Joined: 1/17/2006 Last visit: 7/19/2024 Posts: 800 Rating: (63) |
Hi T.O. Tomorrow I will give you a script (and program) that will do the trick! Hope I have the time to do it Jaap |
1/15/2009 10:04 AM | |
Joined: 1/17/2006 Last visit: 7/19/2024 Posts: 800 Rating: (63) |
Hi T.O., Sorry my script is for sending SMS and buzzer text. I thought it was also for sending email. But just search the forum and you will find wat you are looking for e.g.: /tf/WW/en/Posts/25111 Good luck, Jaap |
1/21/2009 2:31 PM | |
Posts: 12 Rating: (1) |
can you describe what doesn't work? did you try to execute the sendmail.exe from the command line? if that doesn't work, something is wrong with your mail settings (smtpserver, username, password etc.) i found some related forum topics Automated Email and Notices by e-mail |
Last edited by: joost at: 1/21/2009 2:32 PM |
|
This contribution was helpful to1 thankful Users |
7/23/2013 9:47 AM | |
Joined: 4/24/2009 Last visit: 8/20/2024 Posts: 2682 Rating: (135) |
New question splitted to script for sending sms messages Best regards O_Moderator |
Follow us on