system.net.mail problems

Hi everyone, I've trying to use the system.net.mail namespace to send emails with the follwing code:

Private Sub Envio_Correo(ByVal ruta As String)

Dim correo As New MailMessage

correo.From = New MailAddress("b98123839@usmp.edu.pe")

correo.To.Add("amonasiq@usmp.edu.pe")

correo.Subject = "Archivo de Confirmacion de matricula"

correo.Body = "Se adjunto archivo de confirmacion de matricula de su respectiva facultad"

correo.IsBodyHtml = False

'correo.Attachments.Add(New Attachment(ruta))

correo.Priority = MailPriority.Normal

'Crando la instancia del SMTP cliente

Dim smtp As New SmtpClient

smtp.Host = "mail.usmp.edu.pe"

'smtp.Port = 25

'smtp.UseDefaultCredentials = True

Try

smtp.Send(correo)

Catch ex As SmtpException

lMenErr.Text = "Paso 4: Enviando el correo: " + ex.Message.ToString()

lMenErr.ForeColor = System.Drawing.Color.Red

End Try

End Sub

But everytime gives me the same error :

"Mailbox unavailable. The server response was: Error: Message content rejected"

Both addresses are ok and the same code with the old namespace system.web.mail works fine, anyone have a clue on what's wrong with my code

Regards

Alfredo Monasi




Answer this question

system.net.mail problems

  • Kim Madsen

    Mailbox could be unavailable for various reasons:

    1) email systems could be down

    2) invalid email address supplied (typing error for example)

    and other reasons too - in future, please can you translate in english any errors, as it will help us (non spanish speakers etc..) to understand more :-)

    just dishing out my thoughts at the moment



  • Ty Y

    maybe you should think about the authentiation......
  • mlewus

    But why it works with the old namespace without authetication and now needs authetication with the system.net.mail



  • Ronaldlee Ejalu

    Hmm, interesting

    Try commenting this line:

    correo.Priority = MailPriority.Normal

    Also try using credentials: either uncoment this line:

    'smtp.UseDefaultCredentials = True

    or explicitly set your own credentials:

    Dim credentials As New NetworkCredential(username, password, domain); //domain is usually an empty string

    Smtp.Credentials = credentials

    Let me know if this worked

    Mariya


  • SteveLK

    .NET Framework is installed and configured in different ways sometimes, sometimes the firewall blocks any communication from the .NET application, sometimes it doesnt - it all depends on the system configuration.

    But as Mariya has suggested, which I support, if it gives something like could not establish connection, then clearly there is a communication problem either at the server end, or from your computer - perhaps firewall blocking the port.



  • Mateusz Rajca

    One thing: I see you're trying on different ports and of course you get different bahavior. Which is the correct port You said that using the old namespace you're able to connect correctly - which pport are you using with it.

    Also, as mentioned in the above posts the firewall can be blocking the response from the server - and if the server response never reaches your client then the exception makes sense - could not establish connection

    Mariya


  • pwhitaker

    1) does the server allow SMTP mails to be sent (some servers dont such as MSN and use their own internal way of allowing emails to be sent via the proper msn/hotmail/Windows Live email system)

    2) if it says "Sending failed" or something similar, can you copy and paste the entire exception here (including stack trace/inner exception)



  • AboOmar

    Quoting

    " 1) does the server allow SMTP mails to be sent (some servers dont such as MSN and use their own internal way of allowing emails to be sent via the proper msn/hotmail/Windows Live email system) "

    Yes, the server allow smtp mails to be sent, using the old namespace system.web.mail there is no problem at all using smtp.

    " 2) if it says 'Sending failed' or something similar, can you copy and paste the entire exception here (including stack trace/inner exception) "

    Using port 8080:

      NativeErrorCode 10060 

      Message: "Se produjo un error durante el intento de conexion ya que la parte conectada no respondio adecuadamente tras un periodo de tiempo, o bien se produjo un error en la conexion establecida ya que el host conectado no ha podido responder" String
      Message "Failure sending mail." 

      StackTrace "   at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
       at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
       at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
       at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
       at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpClient.GetConnection()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)" String

    Using a default port I get the following error:

      StatusCode MailboxUnavailable {550} System.Net.Mail.SmtpStatusCode

      Message "Mailbox unavailable. The server response was: Error: Message content rejected" String

      InnerException Nothing 




  • Davids Learning

    Hi Mariya, with the old namespace I didn't set any port, I guess used the default port (25)

    But if the firewall is the problem why is still working with the old namespace in the same machine

    Kryor



  • robertje

    could be but I would have most likely thought that it wouldnt communicate at all giving an IOException instead or something of that nature.

  • BALA SINGAM

    Hi Mariya, tried the way you recommend me but I still got the same error, I don't set a port but if I use the 8080 port the error changes to "sending email failure" instead the other one.

    Do you have any other suggestion

    Here is my code:

    Private Sub Envio_Correo(ByVal ruta As String)

    'Creando la instancia del mensaje

    Dim correo As New MailMessage

    correo.From = New MailAddress("b98123839@usmp.edu.pe")

    correo.To.Add("amonasiq@usmp.edu.pe")

    correo.Subject = "Archivo de Confirmacion de matricula"

    correo.Body = "Se adjunto archivo de confirmacion de matricula de su respectiva facultad"

    correo.IsBodyHtml = False

    'correo.Attachments.Add(New Attachment(ruta))

    'correo.Priority = MailPriority.Normal

    'Creando Credenciales

    'Dim usuario As String = "user"

    'Dim contrasena As String = "password"

    'Dim dominio As String = Nothing

    'Dim Credenciales As New NetworkCredential(usuario, contrasena, dominio)

    'Creando la instancia del SMTP cliente

    Dim smtp As New SmtpClient

    With smtp

    .Host = "mail.usmp.edu.pe"

    '.Port = 25

    .UseDefaultCredentials = True

    '.Credentials = Credenciales

    End With

    Try

    smtp.Send(correo)

    Catch ex As SmtpException

    lMenErr.Text = "Paso 4: Enviando el correo: " + ex.Message.ToString()

    lMenErr.ForeColor = System.Drawing.Color.Red

    End Try

    End Sub



  • Iggy Kay

    I think these codes may help you!

    Imports System.Net

    Imports System.Net.Mail

     

    Using mailMessage As New MailMessage()

    With mailMessage

                .To.Add("yourname@domain.com")

                .From = New MailAddress("myname@anotherdomain.com", "My Display Name")

                .Subject = "This is the subject"

                .Body = "REPLACE WITH MESSAGE TEXT"

          End With

     

          Dim username As String = "yourname"

          Dim password As String = "pass@word"

          Dim credentials As New NetworkCredential(username, password)

     

          Dim client As New SmtpClient()

    With client

                .Host = "smtp.mail.yahoo.de"

                .Port = 587

                .Credentials = credentials

                .Send(mailMessage)

    End With

    End Using


  • R.Tutus

    Quoting

    "1) email systems could be down" not the case I just use outlook with the smtp server and it's fine

    " 2) invalid email address supplied" the mail coounts are checked and are valid ones

    and sorry for the spanish post :-P

    Could be a firewall problem



  • Rick_in_Alpharetta

    Can you post the old code and the new code and get a Netmon sniff on both and then we'll compare and see what the problem is.

    Mariya


  • system.net.mail problems