Create C Program Send Email Recipient Q37044641

Create a C++ Program that will send an email to a recipientCreate a C++ Program that will send an email to a recipient Show transcribed image text Create a C++ Program that will send an email to a recipient


Solution


if (!socket.Create(0, SOCK_STREAM))
{
AfxMessageBox(“Could not create socket!”);
res=socket.GetLastError();
return;
}

if (!socket.Connect(m_SmtpServer, 25))
{
TRACE(sendbuf);
AfxMessageBox(“Could not connect to SMTP Service onserver!”);
res=socket.GetLastError();
socket.Close ();
return;
}

if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError();
socket.Close ();
return;
}
// Generate and send lp check request to socket

strcpy(command,”EHLO MY_APPLICATION”);
len=strlen(command);
command[len]=0x0D;
command[len+1]=0x0A;
len++;
if (socket.Send (command,len+1)==SOCKET_ERROR )
{
res=socket.GetLastError();
socket.Close ();
return;
}
if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError();
socket.Close ();
return;
}
if((returnbuf[0]==’2′)&&(returnbuf[1]==’5′)&&(returnbuf[2]==’0′))
{}
else
{
AfxMessageBox(“EHLO command not understood by server!”);
socket.Close ();
return;
}
char size[10];
sprintf(size,”%d”,strlen(sendbuf));
strcpy(command,”MAIL From:<“);
strcat(command,m_SmtpFrom);
strcat(command,”> “);
strcat(command,”SIZE=”);
strcat(command,size);
len=strlen(command);
command[len]=0x0D;
command[len+1]=0x0A;
len++;
if (socket.Send (command,len+1)==SOCKET_ERROR )
{
res=socket.GetLastError();
socket.Close ();
return;
}
memset(returnbuf,0,1024);
if (socket.Receive(returnbuf, 1024, 0)==SOCKET_ERROR)
{
res=socket.GetLastError();
socket.Close ();
return;
}
if((returnbuf[0]==’2′)&&(returnbuf[1]==’5′)&&(returnbuf[2]==’0′))
{}
else
{
CString Message;
Message=”From Field is invalid!

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.