Page 1 of 3

How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 6:46 pm
by emreozpalamutcu
I using visual studio 2010 C++ Windows form application with net framework 4 and I want to send a simple text email without any login requirement. The code will read the text in richtextbox1 and email it to my email. which is custom email for example : example@custom.com

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 6:48 pm
by MrAksel
I know how to do it in VB.NET and eventually C#, but not C++ :(

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 7:00 pm
by emreozpalamutcu
Can you do a search for me, I'm doing a search for 13 hours, did you use SMTP to send email?

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 8:18 pm
by mandai
SMTP is the simplest way of sending mail. You can use this:
Code: Select all
using namespace System::Net::Mail;
Code: Select all
	private: System::Void btnSend_Click(System::Object^  sender, System::EventArgs^  e) {

            SmtpClient^ sc = gcnew SmtpClient();
            sc->Host = "localhost";
            sc->Port = 25;

            MailMessage^ mm = gcnew MailMessage();
            mm->From = gcnew MailAddress("user@source");
            mm->To->Add(gcnew MailAddress("example@custom.com"));

            mm->Body = richTextBox1->Text;

            sc->Send(mm);
			 }

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 8:35 pm
by emreozpalamutcu
Hi again your code compiles fin however when i click the button to send it i get this error: An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 9:23 pm
by Snyper345
emreozpalamutcu wrote:
Hi again your code compiles fin however when i click the button to send it i get this error: An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
show him/us your code so we can see if you have done something wrong

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 9:40 pm
by emreozpalamutcu
it's the code above the one mandai posted

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 9:46 pm
by Snyper345
emreozpalamutcu wrote:
it's the code above the one mandai posted
well im sure youll have to change the host etc.
also check if por 25 is open @ http://www.yougetsignal.com/tools/open-ports/ but im sure it doesnt need to be opened...

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 9:49 pm
by emreozpalamutcu
I know that SMTP is port 25 it says it on the website to and it's closed from my ip and i don't know how to open it and it might be the host any suggestions

Re: How to email a simple plain text on windows form application

Posted: Wed Jun 22, 2011 9:52 pm
by emreozpalamutcu
I just realised i can right anything on the ip bit and i wrote local host with port 25 and it's open any other ideas.