I'm trying to send an email using telnet in C++. I've done it before in regular command prompt, the log went like this:
Code:
telnet /f C:\log.txt mail.mycbsi.com 25
220 pbrane.mycbsi.net ESMTP Postfix
helo x
250 pbrane.mycbsi.net
mail from:[email protected]
250 Ok
rcpt to:[email protected]
250 Ok
data
354 Please start mail input.
This is a test message
.
250 Mail queued for delivery.
quit
221 Closing connection. Good bye.
C:\>exit
And the email was sent, it worked. Now I'm trying to send the same email through C++:
Code:
#include <iostream>
using namespace std;
int main()
{
system("telnet mail.mycbsi.com 25");
system("helo x");
system("mail from: <[email protected]>");
system("rcpt to: <[email protected]>");
system("data");
system("Test Message");
system(".");
system("quit");
system("pause");
}
When I run the program, the only thing that comes up is:
Code:
Connecting to mail.mycbsi.com...
^That flashes quickly^ And then:
Code:
220 pbrane.mycbsi.net ESMTP Postfix
Then nothing happens, it sits there. I think the problem is that the commands are executed too fast, and by the time telnet has connected, the commands are already run.
I also have another problem. I'm trying to make it so you can type in the command to execute on the system. I've tried this:
Code:
#include <iostream>
using namespace std;
int main()
{
char cmd[11];
cout<<"Enter the command: ";
cin>>cmd;
system(cmd);
system("pause");
}
but no luck, it doesn't work. Overall, I'm trying to make a program where whatever is input into the program is emailed to me. To do this, I need to be able to input a variable into the system.
Thanks for any help in advance!