none
i got error while sending email via smtp RRS feed

  • Question

  • i got error when sending email via smtp in a wen application by vb.NET

    the error was:

    The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

    the code was :

     Dim mm As New MailMessage(TextBox1.Text, TextBox2.Text)
                mm.Body = "bbb"
                mm.Subject = "sss"



              
                Dim sc As New SmtpClient()
                sc.Host = "smtp-mail.outlook.com"  ' "smtp.live.com"
                sc.Port = 25
                sc.EnableSsl = True
                sc.DeliveryMethod = SmtpDeliveryMethod.Network
                sc.UseDefaultCredentials = False
                sc.Credentials = New System.Net.NetworkCredential("abdellahgogop@hotmail.com", _
                                                  "******************")

                sc.Send(mm)

    Sunday, March 10, 2019 1:29 PM

All replies

  • Hello,

    Try smtp.office365.com for the host and also try both 25 and 587 for the port.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, March 10, 2019 2:14 PM
    Moderator
  • thanks but:

    it does not work on a server, but works on localhost,

    in server mode: the port=25 gives the error noted above, the port=587 gives :

    System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission line of code in pointed to the           sc.Port = 587

    Sunday, March 10, 2019 2:26 PM
  • i am on a webapplication project
    Sunday, March 10, 2019 2:27 PM
  • The MailMessage.From must be your real outlook email address
     (with port 587 )
    • Edited by Castorix31 Sunday, March 10, 2019 2:33 PM
    Sunday, March 10, 2019 2:30 PM
  • to castorix31, if we consider that you are correct, why the code works just on a localhost and not on a server??? it does not work after testing
    Sunday, March 10, 2019 2:40 PM
  • Hi, 

    I think you can use this snippet it works well with (hotmail.com, outloo.com,yahoo.com and gmail.com)

      Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
            Dim mailfrom As String = txtEmailFrom.Text
            Dim mailPass As String = txtEmailPassword.Text
            Dim mailto1 As String = txtEmailTo1.Text
            Dim mailto2 As String = txtEmailTo2.Text
            Dim mail As String = txtEmailTo1.Text
            Dim subject As String = txtSubject.Text
            Dim Emailmessage As String = txtMessage.Text
            Dim emailattach As String = txtAttach.Text
            Dim emailattach1 As String = txtAttach1.Text
            Dim emailattach2 As String = txtAttach2.Text
            Dim mailname As String = txtEmailTo4.Text
    
            If Len(Trim(mailfrom)) = 0 Then
                MsgBox("Your Email can not be empty", MsgBoxStyle.Exclamation, "Record Required")
                txtEmailFrom.Focus()
                Exit Sub
            End If
    
            If Len(Trim(mailPass)) = 0 Then
                MsgBox("Password can not be empty", MsgBoxStyle.Exclamation, "Record Required")
                txtEmailPassword.Focus()
                Exit Sub
            End If
    
            If Len(Trim(mailto1)) = 0 Then
                MsgBox("Sending Email to can not be empty", MsgBoxStyle.Exclamation, "Record Required")
                txtEmailTo1.Focus()
                Exit Sub
            End If
    
            Dim msg As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage
    
            msg.To.Add(mailto1) 
            If Len(Trim(txtEmailTo2.Text)) <> 0 Then
                msg.To.Add(mailto2)
            End If
    
            msg.From = New MailAddress(mailfrom, mailname, System.Text.Encoding.UTF8)
            msg.Subject = subject
            msg.SubjectEncoding = System.Text.Encoding.UTF8
            msg.Body = Emailmessage
            msg.BodyEncoding = System.Text.Encoding.UTF8
            msg.IsBodyHtml = False
            msg.Priority = MailPriority.High
            Dim client As SmtpClient = New SmtpClient
            
            client.Credentials = New System.Net.NetworkCredential(mailfrom, mailPass)
            client.EnableSsl = True
    
            If mailfrom.Contains("@yahoo.com") Then
                client.Port = 587
                client.Host = "smtp.mail.yahoo.com"
            ElseIf mailfrom.Contains("@hotmail.com") OrElse mailfrom.Contains("@outlook.com") OrElse mailfrom.Contains("@live.com") Then
                client.Port = 587
                client.Host = "smtp.live.com"
            ElseIf mailfrom.Contains("@gmail.com") Then
                client.Port = 587
                client.Host = "smtp.gmail.com"
            End If
            
    
            If txtAttach.Text <> "" Then
                Dim data As Attachment = New Attachment(emailattach) 
                msg.Attachments.Add(data)
            End If
    
            If txtAttach1.Text <> "" Then
    
                Dim data1 As Attachment = New Attachment(emailattach1) 
               
                msg.Attachments.Add(data1)
            End If
    
            Try
                client.Send(msg)
                MsgBox("Email has been sent ",
                   MsgBoxStyle.Information, "Sending Email")
            Catch ex As System.Exception
                MsgBox("Sorry, Sending Failed")
            End Try
        End Sub

    You can skip attachment if you don't use it 

    hope it helps........................

     

    Regards From Amr_Aly

    Sunday, March 10, 2019 7:25 PM
  •  i am on an ASP.NET application, the applcation works in localhost mode , but when it is uploaded , it does not work and the following error is shown:

    The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL

    Thursday, March 21, 2019 9:49 PM
  •  i am on an ASP.NET application, the applcation works in localhost mode , but when it is uploaded , it does not work and the following error is shown:

    The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL

    I think you need to configure the "Less Secure App." ...It's in gmail very easy to configure but in hot mail i don't know because it works with me with no problems ....

    good luck


    Regards From Amr_Aly

    Thursday, March 21, 2019 10:05 PM