Click here to Skip to main content
15,886,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button1_Click(object sender, EventArgs e)
{
   string date = DateTime.Now.ToShortDateString();
   string time = DateTime.Now.ToShortTimeString();
   MailMessage mail = new MailMessage();
   SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
   mail.From = new MailAddress("keylessenc2015@gmail.com");
   mail.To.Add(textBox1.Text);
   mail.Subject = textBox2.Text;
   mail.Body = richTextBox1.Text;

   System.Net.Mail.Attachment attachment;
   attachment = new System.Net.Mail.Attachment(textBox3.Text);
   mail.Attachments.Add(attachment);

   System.Net.Mail.Attachment attachment1;
   attachment1 = new System.Net.Mail.Attachment(textBox4.Text);
   mail.Attachments.Add(attachment1);

   SmtpServer.Port = 587;
   SmtpServer.Credentials = new System.Net.NetworkCredential("keylessenc2015@gmail.com", "******");
   SmtpServer.UseDefaultCredentials = false;
   SmtpServer.EnableSsl = true;
   SmtpServer.Send(mail);
   MessageBox.Show("Mail Send");
   insert(date,time);
}

public void insert(string d,string t)
{
   con.Open();
   SqlCommand cmd = new SqlCommand("insert into [transaction](t_date,t_time,user_s1_email,user_s2_email,user_code) values('" + d + "','" + t + "','" + textBox3.Text + "','" + textBox4.Text + "','" + id+ "')", con);
   cmd.ExecuteNonQuery();
   con.Close();
}


i am getting error in SmtpServer.Send(mail);
Posted
Updated 27-Jan-15 23:55pm
v2
Comments
_Asif_ 28-Jan-15 5:35am    
a simple google search will give you hundred of answers
Member 11166005 28-Jan-15 5:38am    
can u explain me.i am not getting
_Asif_ 28-Jan-15 5:41am    
Try this

https://www.google.com.pk/webhp?sourceid=chrome-instant&rlz=1C1RNZZ___PK587PK587&ion=1&espv=2&ie=UTF-8#q=5.5.1%20authentication%20required

1 solution

This may help you try this :

Try
           Dim Smtp_Server As New SmtpClient
           Dim e_mail As New MailMessage()
           Smtp_Server.UseDefaultCredentials = False
           Smtp_Server.Credentials = New Net.NetworkCredential("email", "password")
           Smtp_Server.Port = 587
           Smtp_Server.EnableSsl = True
           Smtp_Server.Host = "smtp.gmail.com"

           e_mail = New MailMessage()
           e_mail.From = New MailAddress(txtemail.Text)
           e_mail.To.Add(txtemail.Text)
           e_mail.Subject = "Email Sending"
           e_mail.IsBodyHtml = False
           e_mail.Body = txtMessage.Text
           Smtp_Server.Send(e_mail)
           MsgBox("Mail Sent")
       Catch error_t As Exception
           MsgBox(error_t.ToString)
       End Try
 
Share this answer
 

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