Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Forum » x-Forum » Question

For sending an Email

why this code is not working ?

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = neSmtpClient("smtp.gmail.com");
mail.To.Add("client address");

mail.Subject = "Subject";
mail.IsBodyHtml = true;
mail.Body = "Body";

SmtpServer.Port = 587;

SmtpServer.Credentials=newSystem.Net.NetworkCredential("vikaspadhyay051@gmail.com", "my password");

SmtpServer.EnableSsl = true;
catch (Exception ex)
Response.Write("Could not send the e-mail - error: " + ex.Message);

Posted by vikasg 2018-09-12 09:02:49

Hi Vikasg, 
Are you getting any error ? or just code doesn't work without throwing any error.

C++ user image Admin posted 2018-09-12 10:28:49

Code does not working without throwing any error

C++ user image vikasg posted 2018-09-12 10:35:39

//this should work

MailMessage mail = new MailMessage("vikasupadhyay051@gmail.com", "cppbuzz@gmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
mail.Subject = "Email check for Vikas";
mail.Body = "Hi, CppBuzz";

//let us update if it doesn't work

C++ user image admin posted 2018-09-12 19:46:40

Not working

C++ user image vikasg posted 2018-09-15 06:27:46

Following info_n can help.
SMTP server may be requires user/password as basic authentication.
Get SMTP authentication details. Than try. SMTP may requires authentication. It is called user credentials you find and program with it.It could be user based.

C++ user image Patel Dhananjay posted 2018-09-16 21:12:02

Your Answer

Ask New Question