C# : Failure sending mail

  • Thread starter Thread starter Shriram Dixit
  • Start date Start date
S

Shriram Dixit

Guest
I have created a application, in that I have give a option to send a mail. I got an error while sendig a mail like "Failure sending mail. " .For that I have given my code below, please help me to correct it
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;

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

private void label3_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.Timeout = 100000;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("ramd9977", "@9552670526@", "gmail.com");
MailMessage msg = new MailMessage();
msg.To.Add(textBox1.Text);
msg.From = new MailAddress("ramd9977@gmail.com");
msg.Subject = textBox2.Text;
msg.Body = textBox4.Text;
Attachment data = new Attachment(textBox3.Text);
msg.Attachments.Add(data);
client.Send(msg);
MessageBox.Show("Successfully Sent Message.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
textBox3.Text = dlg.FileName.ToString();
}
}
}
}

.
Shriram Dixit Acty System India Ltd Programmer

Continue reading...
 
Back
Top