Email not send .What is this error

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Net;
using System.Windows.Forms;
using System.Net.Mail;
using System.Threading.Tasks;

namespace send_email_new
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void existbutton_Click(object sender, EventArgs e)
        {

            Application.Exit();

        }

        private void sendbutton_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress(fromtextBox.Text, "Usmanzia");
                msg.To.Add(new MailAddress(totextBox.Text));
                msg.Subject = subjecttextBox.Text;
                msg.Body = bodytextBox.Text;
                msg.IsBodyHtml = true;
                if (labelpath.Text.Length > 0)
                {
                    if (System.IO.File.Exists(labelpath.Text))
                    {
                        msg.Attachments.Add(new Attachment(labelpath.Text));
                    }

                }
                SmtpClient stm=new SmtpClient();

                stm.Host="stm.gmail.com";
                stm.Credentials=new NetworkCredential(fromtextBox.Text,passwordtextBox.Text);
                stm.EnableSsl=true;
                stm.Send(msg);
                MessageBox.Show("Message send");

            }

            catch(Exception ex)
            {
                MessageBox.Show(ex.Message,"Message",MessageBoxButtons.OK,MessageBoxIcon.Error);
                //sendbutton.BackColor = Color.Red;
                //MessageBox.Show("Check password");

            }
        }

        private void labelpath_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                labelpath.Text = openFileDialog1.FileName;
                labelpath.Visible = true;

            }
        }

    }
}

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.