Raised This Month: $ Target: $400
 0% 

sending email via sockets


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 02-22-2006 , 07:49   sending email via sockets
Reply With Quote #1

Hello,
I've tryed to send an email with the smtp protocol and sockets.
But it isn't working

Code:
sendMail( server[], port, to[], from[], subject[], text[] ) {     static buff[1024];     static socket;     static error;     static len;     socket = socket_open( server , port, SOCKET_TCP, error );     if( error )         return error;             len = format( buff, 1023, "HELO %s^r^n", server );     socket_send( socket, buff, len );         len = format( buff, 1023, "MAIL FROM <%s>^r^n", from );     socket_send( socket, buff, len );         len = format( buff, 1023, "RCPT TO <%s>^r^n", to );     socket_send( socket, buff, len );         len = format( buff, 1023, "DATA ^r^n" );     socket_send( socket, buff, len );         len = format( buff, 1023, "SUBJECT: %s^r^n%s^r^n.^r^n", subject, text );     socket_send( socket, buff, len );         socket_close(socket);         return 0; }

the function returns 0, but I don't receive an email.

I use this params:
server: my mailserver
port: 25
to: [email protected]
from: [email protected]
subject: 1337 Test
text: this is a test mail

I've tryed socket_send and socket_send2, but both natives aren't working

Regards
Greenberet
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 02-22-2006 , 08:14  
Reply With Quote #2

try using len += instead of len =

The problem is its sending the length of buffer as just the length of the subject and text so the email doesnt get enought information to send.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
KoST
Senior Member
Join Date: Jul 2005
Old 02-22-2006 , 09:59  
Reply With Quote #3

change this:
Code:
MAIL FROM
RCPT TO
into this:
Code:
MAIL FROM:
RCPT TO:
and you forgot to send a single '.' on a line to tell the mailserver that the mail data is complete. QUIT command is also missing..
__________________
KoST is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 02-22-2006 , 10:42  
Reply With Quote #4

ty Kost
i changed it, but it is still not working
btw. the single dot wasn't missing i had it in the same string as "SUBJECT"^^
Code:
sendMail( server[], port, to[], from[], subject[], text[] ) {     static buff[1024];     static socket;     static error;     static len;         socket = socket_open( server , port, SOCKET_TCP, error );     if( error )         return error;             len = format( buff, 1023, "HELO %s^r^n", server );     socket_send( socket, buff, len );         len = format( buff, 1023, "MAIL FROM:<%s>^r^n", from );     socket_send( socket, buff, len );         len = format( buff, 1023, "RCPT TO:<%s>^r^n", to );     socket_send( socket, buff, len );         len = format( buff, 1023, "DATA^r^n" );     socket_send( socket, buff, len );         len = format( buff, 1023, "SUBJECT:%s^r^n%s^r^n", subject, text );     socket_send( socket, buff, len );         len = format( buff, 1023, ".^r^n" );     socket_send( socket, buff, len );         len = format( buff, 1023, "QUIT" );     socket_send( socket, buff, len );             socket_close(socket);         return 0; }

@suicide
ty for your help, but "len =" is correct^^

Regards
Greenberet
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
KoST
Senior Member
Join Date: Jul 2005
Old 02-22-2006 , 11:29  
Reply With Quote #5

1. your source seem fine, except ^r^n after QUIT missing..
2. i'm not sure if you can send all the commands once, or if you have to wait for the response from the mail server. i would try to get the responses from the mail server, this would help you to know why this isn't working..
__________________
KoST is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 02-22-2006 , 12:07  
Reply With Quote #6

Oh, I read through it quick and only saw one socket_send().
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode