Locked Email Sending Failed

  • lundi 30 avril 2012 13:14
     
      A du code

    when ever i try to send mail through my webpage than all time i receive Exception:

    "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. i1sm16009352pbv.49"

    Mycode is as belove

     MailMessage msgMail = new MailMessage();
            MailMessage myMessage = new MailMessage();
            if (FileUpload1.HasFile)
            {
                FileUpload1.SaveAs(Server.MapPath("~/upload/" + FileUpload1.FileName));
                lbl_attach.Text = Server.MapPath("~/upload/" + FileUpload1.FileName);
                //FileUpload1.SaveAs("C:\\Program Files (x86)\\Common Files\\microsoft shared\\DevServer\\10.0\\" + FileUpload1.FileName);
                //Label3.Text = FileUpload1.FileName;
                myMessage.Attachments.Add(new Attachment(lbl_attach.Text));
            }
            myMessage.From = new MailAddress("XXXXX@gmail.com");
            myMessage.To.Add("'"+cb_recipient.SelectedValue+"'");
            myMessage.Subject = "" + txt_subject.Text + "";
            myMessage.IsBodyHtml = true;
            myMessage.Body = "" + txt_body.Text + "";
            //myMessage.Attachments.Add(new Attachment(txt_attachment.Text));
            SmtpClient mySmtpClient = new SmtpClient();
            //SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("XXXXX@gmail.com","XXXXX");
            mySmtpClient.Host = "smtp.gmail.com";
            //SmtpServer.EnableSsl = true;
            mySmtpClient.UseDefaultCredentials = false;
            mySmtpClient.Credentials = myCredential;
            mySmtpClient.ServicePoint.MaxIdleTime = 1;
            mySmtpClient.Send(myMessage);
            myMessage.Dispose();
    Please help...

Toutes les réponses

  • lundi 30 avril 2012 16:06
     
     

    thr adding the delivery method.  In Net 4.0 you are required to set this parameter, otherwise, it willuse the account setup up on your local computer.  You can see what account is setupon your computer my going into control panel mail.  The network option instead of using the account on your computer connects over your network to the host property set in the client.

    the other reason for the error message you are getting can be caused by a firewall blocking SMTP protocol.

    SmtpClient

    mySmtpClient = new SmtpClient();

    mySmtpClient.DeliveryMethod =

    SmtpDeliveryMethod.Network;

    jdweng

  • lundi 30 avril 2012 17:38
     
     

    Thank you, Joel Engineer(MCC)

    I try your suggestion but still i got error same, as mention in my question.

    my code work properly but after updating visual studio 2010 with sp1 from windows7 update, every time i getting this exception.
    any solution for that?

    Can Kaspersky Antivirus affect the SMTP?(But i try with disable Antivirus but not got any satisfied solution).

    Help.

    • Modifié nibagadiya lundi 30 avril 2012 17:50
    •  
  • lundi 30 avril 2012 18:12
     
     

    I usually start by hoving over the variables that give the error and start by look at the errors in the client and ports.  Some times this helps.  In this case I've checked the web and found the error is due to the credentals failing.  the website beow references the web.config file.   I searched my PC and found these files under the windows/framework folders.

    http://forums.asp.net/t/1243641.aspx

    I wondering if you take the program that was compiled under XP and run under win7 do you get the same error.  Also if you cna compile on win7 and run on an XP machine. I'm trying to determine if your problem is with the compiler or the PC.

    The website below adds the following crediatials to the email.  Maybe these setting aren't being adding automatically on your PC.

    msgMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
     msgMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "info@mydomain.com");
     msgMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "mypassword");
    msgMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "587");

    http://forums.asp.net/p/1798047/4956304.aspx/1?How+To+issue+STARTTLS+command


    jdweng