Click to See Complete Forum and Search --> : My program doesn't work! Please help.


harkoslav
September 18th, 2010, 08:16 AM
Hello everyone. I made this little program for sending mail, everything looks fine (for me), got no errors, debugging without a problem. Only problem is that its not working. My program doesn't send mail. Can you please tell me why? Thanks.




// msdnproba2.cpp : main project file.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>

using namespace System;
using namespace System::Net::Mail;
using namespace System::Net;
using namespace std;

int main(array<System::String ^> ^args)
{


cout << "Sending mail..."<< endl;

char f;
cin >> f;


return 0;
}

static void Mail_test1( String^ server, int port )
{
String^ to = L"mymail1@yahoo.com";
String^ from = L"mymail2@yahoo.com";
String^ subject = L"This is subject!";
String^ body = L"Hello! This is a test.";
MailMessage^ message = gcnew MailMessage( from,to,subject,body );
SmtpClient^ client = gcnew SmtpClient( "smtp.mail.yahoo.com , 465" );


client->Credentials = gcnew NetworkCredential("mymail2@yahoo.com", "mypassword", "smtp.mail.yahoo.com");
client->UseDefaultCredentials = false;

ServicePoint^ p = client->ServicePoint;
Console::WriteLine( L"Connection lease timeout: {0}", p->ConnectionLeaseTimeout );
client->Send( message );
client->~SmtpClient();


}

Sharpie
September 18th, 2010, 08:37 AM
YOU don't need your input "f", why is it there ?
You didn't call your function, only input your nonsense irrelevant f

harkoslav
September 18th, 2010, 09:37 AM
Oh God. I didn't program for a WHILEEE. I forgot everything. :D
I changed the problem now, but still my program doesn't work. Any clue?



// test3.cpp : main project file.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>

using namespace System;
using namespace System::Net::Mail;
using namespace System::Net;
using namespace std;



static void mailtest1 ( String^ server, int port )
{
String^ to = L"mymail1@yahoo.com";
String^ from = L"mymail2@yahoo.com";
String^ subject = L"This is subject!";
String^ body = L"Hello! This is a test.";
MailMessage^ message = gcnew MailMessage( from,to,subject,body );
SmtpClient^ client = gcnew SmtpClient( "smtp.mail.yahoo.com , 465" );




client->Credentials = gcnew NetworkCredential("mymail2@yahoo.com", "password", "smtp.mail.yahoo.com");
client->UseDefaultCredentials = false;

ServicePoint^ p = client->ServicePoint;
Console::WriteLine( L"Connection lease timeout: {0}", p->ConnectionLeaseTimeout );
client->Send( message );
client->~SmtpClient();


}





int main(array<System::String ^> ^args)
{
mailtest1;

return 0;
}

GCDEF
September 18th, 2010, 11:52 AM
You may want to ask in one of the .net forums.

cilu
September 21st, 2010, 08:57 AM
Problem 1:

mailtest1 ( String^ server, int port )

you never use server and port, why don't you get rid of them?

Problem 2

int main(array<System::String ^> ^args)
{
mailtest1;

return 0;
}

This shouldn't compile. You should call mailtest1() passing the right arguments, or if you get rid of the server and port parameters, without any arguments.

int main(array<System::String ^> ^args)
{
mailtest1();

return 0;
}

harkoslav
September 25th, 2010, 02:26 PM
I fixed that. Thanks for the reply , but my mail still isn't sent.