Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Can you help me why my script problem at CLR forms application,

An unhandled exception of type 'System.FormatException' occurred in System.dll
check this out
http://i59.tinypic.com/29gel53.jpg[^]

Regards

Ogawa Kazuma
Posted
Comments
Sergey Alexandrovich Kryukov 2-Dec-14 10:19am    
It could be too many reasons for failure to send mail, so your post makes no sense. And please, don't reference a picture where you could just copy and paste text.
—SA
Ogawa Kazuma 2-Dec-14 22:47pm    
//Source.cpp
#include "stdafx.h"
#include "Gmail.h"

using namespace My19112014;

[STAThreadAttribute]
int main(array<system::string ^=""> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Gmail());
return 0;
}

//Gmail.h
#pragma once

namespace My19112014 {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Net::Mail;

///
/// Summary for Gmail
///

public ref class Gmail : public System::Windows::Forms::Form
{
public:
Gmail(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}

protected:
///
/// Clean up any resources being used.
///

~Gmail()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::GroupBox^ groupBox1;
protected:
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ passwordBox;

private: System::Windows::Forms::TextBox^ emailBox;

private: System::Windows::Forms::GroupBox^ groupBox2;
private: System::Windows::Forms::TextBox^ portBox;

private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::TextBox^ smtpBox;

private: System::Windows::Forms::GroupBox^ groupBox3;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::TextBox^ subjectBox;

private: System::Windows::Forms::TextBox^ toBox;

private: System::Windows::Forms::ProgressBar^ progressBar1;
private: System::Windows::Forms::TextBox^ attachBox;

private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::TextBox^ isiBox;

private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;

private:
///
/// Required designer variable.
///

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

void InitializeComponent(void)
{
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->passwordBox = (gcnew System::Windows::Forms::TextBox());
this->emailBox = (gcnew System::Windows::Forms::TextBox());
this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
this->portBox = (gcnew System::Windows::Forms::TextBox());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->smtpBox = (gcnew System::Windows::Forms::TextBox());
this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button1 = (gcnew System::Windows::Forms::Button());
this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
this->attachBox = (gcnew System::Windows::Forms::TextBox());
this->label7 = (gcnew System::Windows::Forms::Label());
this->isiBox = (gcnew System::Windows::Forms::TextBox());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->subjectBox = (gcnew System::Windows::Forms::TextBox());
this->toBox = (gcnew System::Windows::Forms::TextBox());
this->openFileDialog1 = (gcnew System::Windows
Ogawa Kazuma 2-Dec-14 22:48pm    
cont--

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)

{

openFileDialog1->ShowDialog();
openFileDialog1->Title = "Choose A File To Attach";
attachBox->Text = openFileDialog1->FileName;
}

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)

{


String ^ username;
username = emailBox->Text;
String ^ password;
password = passwordBox->Text;
String ^ server;
server = smtpBox->Text;
String ^ to;
to = toBox->Text;
String ^ subject;
subject = subjectBox->Text;
String ^ body;
body = isiBox->Text;
String ^ attachment;
attachment = attachBox->Text;
progressBar1->Value = 1;
SmtpClient^ smtpserver = gcnew SmtpClient();
progressBar1->Value = 10;
MailMessage^ mail = gcnew MailMessage();
progressBar1->Value = 20;
Attachment^ at = gcnew Attachment(attachment);
progressBar1->Value = 30;
smtpserver->Credentials = gcnew Net::NetworkCredential(username, password);
progressBar1->Value = 40;
smtpserver->Port = 587;
progressBar1->Value = 45;
smtpserver->Host = server;
progressBar1->Value = 50;
smtpserver->EnableSsl = true;
progressBar1->Value = 55;
mail->From = gcnew MailAddress(username);
progressBar1->Value = 60;
mail->Attachments->Add(at);
progressBar1->Value = 66;
mail->To->Add(to);
progressBar1->Value = 70;
mail->Subject = subject;
progressBar1->Value = 80;
mail->Body = body;
progressBar1->Value = 90;
smtpserver->Send(mail);
progressBar1->Value = 100;
MessageBox::Show("Pesan telah dikirimkan","Terkirim");

}
};
}
Richard MacCutchan 2-Dec-14 11:43am    
Are you using a valid userid and password in your credentials?
Ogawa Kazuma 2-Dec-14 22:49pm    
nope, it's valid username and id

1 solution

Hi all,

That's already done by disable my antivirus software

Danke
 
Share this answer
 
Comments
Richard MacCutchan 3-Dec-14 4:03am    
Great idea, that should ensure your system gets infested next time you use the internet.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900