Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good morning guys.

I am working on an application that should send mails to some recipient. I got a mail address tarek@abcd.fr use it to send a mail to tarek@gmail.com. each time I execute my program I got the following message when I send DATA
"553 sorry that domain isn't allowed to be relayed thru this mta (#5.7.1) ovh"

I tried to change my port from 25 to 587 (even 465) but I got the same result.

I am using Visual Studio 2010 on Windows 8. I f you need more information or explanation, you are welcome.

Thank you in advance :)
Posted
Comments
Richard MacCutchan 14-Apr-15 5:29am    
It is usually to do with authentication. Check the settings against your SMTP server.
TAREK BAZINGA 14-Apr-15 6:08am    
I think you were right Richard, because I missed to sent AUTH request. but what shall I sent with, my password or username?
[no name] 14-Apr-15 5:29am    
can u show your code..
in gmail port id 587.
TAREK BAZINGA 14-Apr-15 6:09am    
wsprintf(buff_Sent, "HELO \r\n");
if( send(m_SocketSMTP , buff_Sent , (int)strlen(buff_Sent) , 0) < 0)
{
puts("\n HELO Failed - Sending");
return false;
}
if((Etat_Recu = recv(m_SocketSMTP , buff_recu , sizeof(buff_recu) , 0)) <= 0)
{
puts("\nHELO Failed - Sending");
return false;
}
cout<<"\n"<<buff_recu;
memset (buff_Sent, 0, sizeof (buff_Sent));
memset (buff_recu, 0, sizeof (buff_recu));

//Send MAIL FROM
wsprintf(buff_Sent, "MAIL FROM:<%s>\r\n", m_Sender);//tarek@md2i.fr
cout<<"\nThis is my FROM===>> "<<buff_Sent;
if( send(m_SocketSMTP , buff_Sent , (int)strlen(buff_Sent) , 0) < 0)
{
puts("\n MAIL FROM Failed - Sending");
return false;
}
if((Etat_Recu = recv(m_SocketSMTP , buff_recu , sizeof(buff_recu) , 0)) <= 0)
{
puts("\nMAIL FROM Failed - Receiving");
return false;
}
cout<<"\n"<<buff_recu;
memset (buff_Sent, 0, sizeof (buff_Sent));
memset (buff_recu, 0, sizeof (buff_recu));

//Send RCPT TO
wsprintf(buff_Sent, "RCPT TO:<%s>\r\n", m_Reciep);//
cout<<"\nThis is my TO ===>> "<<buff_Sent;
if( send(m_SocketSMTP , buff_Sent , (int)strlen(buff_Sent) , 0) < 0)
{
puts("\n RCPT TO Failed - Sending");
return false;
}
if((Etat_Recu = recv(m_SocketSMTP , buff_recu , sizeof(buff_recu) , 0)) <= 0)
{
puts("\n RCPT TO Failed - Receiving");
return false;
}
cout<<"\n"<<buff_recu;
memset (buff_Sent, 0, sizeof (buff_Sent));
memset (buff_recu, 0, sizeof (buff_recu));
TAREK BAZINGA 14-Apr-15 6:12am    
I need to add
wsprintf(buff_Sent, "AUTH LOGIN <%s>\r\n", ????);
what shall I put instead of ????

1 solution

You are using the wrong SMTP server (it did not accept mails from the abcd.fr domain) or there is an authentication problem (as already noted by Richard).

Use the same settings as in your mail client for the abcd.fr account (SMTP server, port, authentication method). The settings should be provided by your domain hoster.

[EDIT]
Your SMTP communication is invalid. You can use a telnet client to connect manually and use that as base for your code. See for example How to Use Telnet to Test SMTP Communication[^].

Your actual code has multiple errors (sending HELO instead of EHLO, no authentication).
 
Share this answer
 
v2
Comments
TAREK BAZINGA 14-Apr-15 6:26am    
I did the same settings as in my mail client, but i think it is a problem of authentication, when I sent my request of authentication I got another error "557... YOU HAVE TO LEARN SMTP RFC..." :P
Jochen Arndt 14-Apr-15 6:38am    
You should show the relevant parts of your code (use the green Improve question link to edit your question).

The new error message indicates that your SMTP communication does not follow the standard.

You may check the communication manually using telnet: https://technet.microsoft.com/en-us/library/aa995718%28v=exchg.65%29.aspx
TAREK BAZINGA 14-Apr-15 8:03am    
if (WSAStartup(MAKEWORD(2,2),&wsd) != 0)
{
cout<<"\n Phase Constructor";
cout<<"\n Failed. Error Code : %d ", WSAGetLastError();
}
printf("\n Socket Initialised");

if((m_SocketSMTP = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
{
cout<<"\n Phase Constructor";
cout<<"\n Could Not Create Socket : %d" , WSAGetLastError();
}

cout<< "\n Socket Created";

struct sockaddr_in server;
server.sin_family = AF_INET;//IPPROTO_TCP
server.sin_addr.S_un.S_addr = inet_addr("216.58.192.37");
server.sin_port = htons(587);
if (connect(m_SocketSMTP , (struct sockaddr *)&server , sizeof(server)) < 0)//The SOCKADDR structure is used to store an Internet Protocol (IP) address for a machine participating in a Windows Sockets communication === // Connect needs a socket and a sockaddr structure to connect to
{
puts("\n Connection Error - Phase Connection");
return false;
}

puts("\n Connected to Server");

char buff_Sent[1024];
char buff_recu[1024];
int Etat_Recu;
TAREK BAZINGA 14-Apr-15 8:03am    
I put the following code before starting my requests
Jochen Arndt 14-Apr-15 8:09am    
Code posted in comment is hard to read.

Use the green 'Improve question' link to add such information to your question.

However, the above code is not related to your question (the connection seems to be stablished when you got an error response).

See the link from my updated answer. You should do it using telnet and then send corresponding data from your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900