Im coded here:
private void Send()
{
try
{
string Subject = "This is test mail using smtp settings",
Body = "sad",
ToEmail = txtEmail.Text.Trim();
string SMTPUser = "[email protected]", SMTPPassword = "myPass";
//Now instantiate a new instance of MailMessage
MailMessage mail = new MailMessage();
//set the sender address of the mail message
mail.From = new MailAddress(SMTPUser, "iDOC");
//set the recepient addresses of the mail message
mail.To.Add(ToEmail);
//set the subject of the mail message
mail.Subject = Subject;
//set the body of the mail message
mail.Body = Body;
//leave as it is even if you are not sending HTML message
mail.IsBodyHtml = true;
//set the priority of the mail message to normal
mail.Priority = MailPriority.Normal;
//instantiate a new instance of SmtpClient
SmtpClient smtp = new SmtpClient();
//if you are using your smtp server, then change your host like "smtp.yourdomain.com"
smtp.Host = "smtp.gmail.com";
//chnage your port for your host
smtp.Port = 25; //or you can also use port# 587
//provide smtp credentials to authenticate to your account
smtp.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//if you are using secure authentication using SSL/TLS then "true" else "false"
smtp.EnableSsl = true;
smtp.Send(mail);
}
catch (SmtpException ex)
{
}
}
{
try
{
string Subject = "This is test mail using smtp settings",
Body = "sad",
ToEmail = txtEmail.Text.Trim();
string SMTPUser = "[email protected]", SMTPPassword = "myPass";
//Now instantiate a new instance of MailMessage
MailMessage mail = new MailMessage();
//set the sender address of the mail message
mail.From = new MailAddress(SMTPUser, "iDOC");
//set the recepient addresses of the mail message
mail.To.Add(ToEmail);
//set the subject of the mail message
mail.Subject = Subject;
//set the body of the mail message
mail.Body = Body;
//leave as it is even if you are not sending HTML message
mail.IsBodyHtml = true;
//set the priority of the mail message to normal
mail.Priority = MailPriority.Normal;
//instantiate a new instance of SmtpClient
SmtpClient smtp = new SmtpClient();
//if you are using your smtp server, then change your host like "smtp.yourdomain.com"
smtp.Host = "smtp.gmail.com";
//chnage your port for your host
smtp.Port = 25; //or you can also use port# 587
//provide smtp credentials to authenticate to your account
smtp.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
//if you are using secure authentication using SSL/TLS then "true" else "false"
smtp.EnableSsl = true;
smtp.Send(mail);
}
catch (SmtpException ex)
{
}
}
Im used port 587
My code is not error but is not work. Any guess what to do?
Thanks
My code is not error but is not work. Any guess what to do?
Thanks
Rajeesh MenothPosted Jul 1, 2015, 4:31 AM
Cao Cu HaoPosted Jul 1, 2015, 4:26 AM
I created another email, it worked
Rajeesh MenothPosted Jun 30, 2015, 11:52 PM
using System.IO;using System.Net;
using System.Net.Mail;
using System.Text;
using System.Globalization;
string to = "[email protected]";//To address
string from = "[email protected]";//From address
MailMessage message = new MailMessage(from, to);
if u get the error "SEND EMAIL FROM GMAIL WITH SMTP AUTHENTICATION BUT GOT “5.5.1 AUTHENTICATION REQUIRED” ERROR" then you can follow this below link..message.Subject = txt_subject.text;message.Body = mailbody;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
System.Net.NetworkCredential basicCredential1 = new
System.Net.NetworkCredential("yourmail id", "Password");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicCredential1;
try
{
client.Send(message);
}
catch (Exception ex)
{
throw ex;
}
Ranjit PowarPosted Jun 30, 2015, 11:50 PM
Munesh SharmaPosted Jun 30, 2015, 10:55 PM