problem in Email sending

arjmand

Active member
Joined
Aug 17, 2006
Messages
29
Programming Experience
Beginner
Hi and thank u in advance,
Friends am Using System.Net.Mail to send email, I did it sucessfully on smtp.gmail.com, but our company owns its own smtp server, when i am trying to send the email to it, I get the following exception:
I tried everything the authentication and credentials, but result the same. So if anybody has any ideas, please help
System.Net.Mail.SmtpException was caught
Message="Syntax error, command unrecognized. The server response was: Syntax error, command unrecognised."
Source="System"

Thank you
 
Because I swap between using google and normal authenticated email I wrote two functions that do the trick for me hope you find these usefull

PHP:
Public Function SendAuthenticatedHtml(ByVal username As String, ByVal password As String) As Boolean
        Dim client As New System.Net.Mail.SmtpClient(SmtpServer)

        Dim from As New System.Net.Mail.MailAddress(MailFrom, MailFrom)
        Dim sendTo As New System.Net.Mail.MailAddress(MailTo, MailTo)
        Dim msg As New System.Net.Mail.MailMessage(from, sendTo)
        Dim smtpInfo As New System.Net.NetworkCredential(username, password)

        With msg
            msg.IsBodyHtml = True
            msg.Subject = Subject
            msg.Body = Body
        End With

        Try
            With client
                .UseDefaultCredentials = False
                .Credentials = smtpInfo
                .Send(msg)
            End With
            Return True
        Catch generatedExceptionName As Exception
            Return False
        End Try
    End Function
    Public Function SendGoogleAuthenticatedHtml(ByVal username As String, ByVal password As String) As Boolean
        Dim msg As New System.Net.Mail.MailMessage(MailFrom, MailTo, Subject, Body)
        Dim emailUsername As String = username
        Dim emailPassword As String = password

        Dim basicAuthenticationInfo As New System.Net.NetworkCredential(emailUsername, emailPassword)

        Dim client As New System.Net.Mail.SmtpClient()
        With client
            .Host = SmtpServer
            .Port = 587
            .UseDefaultCredentials = False
            .Credentials = basicAuthenticationInfo
            .EnableSsl = True
        End With

        Try
            client.Send(msg)
            Return True
        Catch generatedExceptionName As Exception
            Return False
        End Try

    End Function
Regards

ScottyB
 
Can you post a snippet of the relevant code that you are using to send the email. I can have a look and see if I see anything.

Regards

ScottyB
 
I used the same code snippet u had placed in ur reply, only change i made was changed the smtp, user name. I thing i would like to say is that when i configure IIS and use SMTPCL.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis where SMTPCL is an object of type system.net.mail.smtpclient, then email is sent. I would have stick to it but my clients dont want to have IIS installed on their systems. Thank u again.
 
Back
Top