locked
somee dont send mail RRS feed

  • Question

  • User665856204 posted

    hello to everyone..

    this is my code

    try
    {
    using (MailMessage mail = new MailMessage())
    {
    mail.From = new MailAddress("selemis1982@gmail.com");
    mail.To.Add(u._email);
    mail.Subject = "Hello sof";
    mail.Body = "<h1>Hello</h1>";
    mail.IsBodyHtml = true;
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    SmtpServer.Port = 587;
    SmtpServer.UseDefaultCredentials = true;
    SmtpServer.EnableSsl = true;
    SmtpServer.Credentials = new System.Net.NetworkCredential("selemis1982@gmail.com", "xxx");
    SmtpServer.Send(mail);
    }
    }
    catch (Exception ex)
    {

    }

    When i run it in Vs2012 everything ok...

    When i upload it to somee server doesnt send mail, and there is no error.

    Help anyone?

    Tuesday, March 22, 2016 11:16 PM

Answers

  • User36583972 posted

    Hi gianestras,

    From your description, You can try the following code. I suggest you try to debug your code, find the error message. This will help us to restore your question.

            [HttpGet]
            [AllowAnonymous]
            [ActionName("SendGmail")]
            public string SendGmail()
            {
                SmtpClient client = new SmtpClient();
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.EnableSsl = true;
                client.Host = "smtp.gmail.com";
                client.Port = 587;
                // setup Smtp authentication
                System.Net.NetworkCredential credentials =
                    new System.Net.NetworkCredential("your_account@gmail.com", "yourpassword");
                client.UseDefaultCredentials = false;
                client.Credentials = credentials;
    
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("your_account@gmail.com");
                msg.To.Add(new MailAddress("destination_address@someserver.com"));
    
                msg.Subject = "This is a test Email subject";
                msg.IsBodyHtml = true;
                msg.Body = string.Format("<html><head></head><body><b>Test HTML Email</b></body>");
                try
                {
                    client.Send(msg);
                    return "OK";
                }
                catch (Exception ex)
                {
                    return "error:" + ex.ToString();
                }
            }

    Also, you can refer the following links.

    Send email using Gmail SMTP Mail Server in ASP.Net:

    http://www.aspsnippets.com/Articles/Send-email-using-Gmail-SMTP-Mail-Server-in-ASPNet.aspx

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 23, 2016 2:39 AM
  • User665856204 posted

    i solved it with this.. google-site-verification: googlexxxxxxxxafdeccc.html

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 23, 2016 5:18 PM

All replies

  • User36583972 posted

    Hi gianestras,

    From your description, You can try the following code. I suggest you try to debug your code, find the error message. This will help us to restore your question.

            [HttpGet]
            [AllowAnonymous]
            [ActionName("SendGmail")]
            public string SendGmail()
            {
                SmtpClient client = new SmtpClient();
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.EnableSsl = true;
                client.Host = "smtp.gmail.com";
                client.Port = 587;
                // setup Smtp authentication
                System.Net.NetworkCredential credentials =
                    new System.Net.NetworkCredential("your_account@gmail.com", "yourpassword");
                client.UseDefaultCredentials = false;
                client.Credentials = credentials;
    
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("your_account@gmail.com");
                msg.To.Add(new MailAddress("destination_address@someserver.com"));
    
                msg.Subject = "This is a test Email subject";
                msg.IsBodyHtml = true;
                msg.Body = string.Format("<html><head></head><body><b>Test HTML Email</b></body>");
                try
                {
                    client.Send(msg);
                    return "OK";
                }
                catch (Exception ex)
                {
                    return "error:" + ex.ToString();
                }
            }

    Also, you can refer the following links.

    Send email using Gmail SMTP Mail Server in ASP.Net:

    http://www.aspsnippets.com/Articles/Send-email-using-Gmail-SMTP-Mail-Server-in-ASPNet.aspx

    Best Regards,

    Yohann Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 23, 2016 2:39 AM
  • User665856204 posted

    goodmorning Yohann...

    I thought exactly your solution 

    return "error:" + ex.ToString();

    while i was coming to my office.

    when i ll go at home il try this and i will tell you the results. thnx a lot...

    Wednesday, March 23, 2016 7:00 AM
  • User665856204 posted

    System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) 

    but when i run it from VS2013 its ok. 

    I upload the project to somee server (somee.com)

    Wednesday, March 23, 2016 4:15 PM
  • User665856204 posted

    i solved it with this.. google-site-verification: googlexxxxxxxxafdeccc.html

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 23, 2016 5:18 PM