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
Can you give a code, I'm doing research on this topic for 13 hours now and I sick and tired of searching. I search the whole Google and there isn't a single answer.
Just do a quick search on SMPT with Winsock in Google and I'm sure you'll come up with something. I don't think it's possible to send an email without a login or server, which is a good thing except for the fact that you spent 13 hours searching for how, and probably explains your 13 hours of research without any answers.
int main(array<String^>^ args)
{
if (args->Length > 1)
{
// Command line argument must the the SMTP host.
SmtpClient^ client = gcnew SmtpClient(args[1]);
// Specify the e-mail sender.
// Create a mailing address that includes a UTF8
// character in the display name.
MailAddress^ from = gcnew MailAddress("jane@contoso.com",
"Jane " + (wchar_t)0xD8 + " Clayton",
System::Text::Encoding::UTF8);
// Set destinations for the e-mail message.
MailAddress^ to = gcnew MailAddress("ben@contoso.com");
// Specify the message content.
MailMessage^ message = gcnew MailMessage(from, to);
message->Body = "This is a test e-mail message sent" +
" by an application. ";
// Include some non-ASCII characters in body and
// subject.
String^ someArrows = gcnew String(gcnew array<wchar_t>{L'\u2190',
L'\u2191', L'\u2192', L'\u2193'});
message->Body += Environment::NewLine + someArrows;
message->BodyEncoding = System::Text::Encoding::UTF8;
message->Subject = "test message 1" + someArrows;
message->SubjectEncoding = System::Text::Encoding::UTF8;
// Set the method that is called back when the send
// operation ends.
client->SendCompleted += gcnew
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your
// callback method to identify this send operation.
// For this example, the userToken is a string constant.
String^ userState = "test message1";
client->SendAsync(message, userState);
Console::WriteLine("Sending message... press c to" +
" cancel mail. Press any other key to exit.");
String^ answer = Console::ReadLine();
// If the user canceled the send, and mail hasn't been
// sent yet,then cancel the pending operation.
if (answer->ToLower()->StartsWith("c") && mailSent == false)
{
client->SendAsyncCancel();
}
// Clean up.
delete message;
client = nullptr;
Console::WriteLine("Goodbye.");
}
else
{
Console::WriteLine("Please give SMTP server name!");
}
}
I got this part of the code in button click event and i think all of it is not meant to be in here but the rest of the code is in right place for sure.
i got another from another guy it compiles fine however when i click to send i get this error: An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll