6 Replies - 346 Views - Last Post: 09 January 2018 - 03:47 PM Rate Topic: -----

#1 ikhlas06  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 325
  • Joined: 20-May 16

how to send email using smtpclient

Posted 07 January 2018 - 01:29 PM

getting an error: Failure sending mail.

i am using vb and smtpclient to send a email. i have a domain and server set up
every thing looks good to me. i can seem to find the issue

 Dim MailClient As SmtpClient = New SmtpClient("117.100.13.11")
            MailClient.Credentials = New Net.NetworkCredential("hostingusername", "hostingpassword")
            Dim Mailmsg As New MailMessage

            Mailmsg.To.Clear()

            Mailmsg.To.Add(New MailAddress("[email protected]"))
            Mailmsg.From = New MailAddress("[email protected])
            Mailmsg.Subject = SubjectS
            Mailmsg.Body = MessageS
            Mailmsg.IsBodyHtml = True
            MailClient.Send(Mailmsg)


Is This A Good Question/Topic? 0
  • +

Replies To: how to send email using smtpclient

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13969
  • View blog
  • Posts: 55,769
  • Joined: 12-June 08

Re: how to send email using smtpclient

Posted 07 January 2018 - 01:59 PM

Did you set '.UseDefaultCredentials ' to false?

Also is your host hotmail? Spam filters get funky when the email claims to be from one place but is bounced from some other server.
Was This Post Helpful? 0
  • +
  • -

#3 ikhlas06  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 325
  • Joined: 20-May 16

Re: how to send email using smtpclient

Posted 07 January 2018 - 02:07 PM

no my email is [email protected]

users can use there own email (ex: hotmail etc..) to send email to me

This post has been edited by andrewsw: 07 January 2018 - 02:14 PM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,484
  • Joined: 12-December 12

Re: how to send email using smtpclient

Posted 07 January 2018 - 02:13 PM

Is that an exact copy of your code? A missing quote suggests that it isn't.

Please copy and paste your exact code, you can still disguise personal information.
Was This Post Helpful? 0
  • +
  • -

#5 ikhlas06  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 325
  • Joined: 20-May 16

Re: how to send email using smtpclient

Posted 07 January 2018 - 02:52 PM

View Postandrewsw, on 07 January 2018 - 02:13 PM, said:

Is that an exact copy of your code? A missing quote suggests that it isn't.

Please copy and paste your exact code, you can still disguise personal information.



Try
            Dim MailClient As SmtpClient = New SmtpClient()
            MailClient.Host = "111.11.111.111"
            MailClient.Credentials = New Net.NetworkCredential("databaseID", "password")
            Dim Mailmsg As New MailMessage

            Mailmsg.To.Clear()

            Mailmsg.To.Add(New MailAddress("[email protected]"))
            Mailmsg.From = New MailAddress(userEmail)
            Mailmsg.Subject =  SubjectS
            Mailmsg.Body = MessageS
            Mailmsg.IsBodyHtml = True
            MailClient.Send(Mailmsg)
        Catch ex As Exception
            myErrorL.Text = "<div class='alert alert-danger' role='alert'>Unable to send an email. " & ex.Message & "</div>"
            Return
        End Try

Was This Post Helpful? 0
  • +
  • -

#6 IronRazer  Icon User is online

  • Custom Control Freak
  • member icon

Reputation: 1491
  • View blog
  • Posts: 3,778
  • Joined: 01-February 13

Re: how to send email using smtpclient

Posted 07 January 2018 - 04:23 PM

Have you tried what modi123_1 has suggested. Set the UseDefaultCredentials property of your SmtpClient to False. From reading a few posts around the internet, it is suggested that you should do it before setting the Credentials property to your new credentials. Here is the last post i read that suggested it fixed their problem.
            MailClient.UseDefaultCredentials = False 'Set prior to setting the new credentials
            MailClient.Credentials = New Net.NetworkCredential("databaseID", "password")



Maybe look into the SmtpClient.EnableSsl Property too.

I am no expert in this subject but, i know i had to set the EnableSsl property to True when sending an email to Yahoo or gmail before. Not sure if you need to or not though.
Was This Post Helpful? 0
  • +
  • -

#7 ikhlas06  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 325
  • Joined: 20-May 16

Re: how to send email using smtpclient

Posted 09 January 2018 - 03:47 PM

it is weird becuase code seem to be right and I did added ssl and usedefault tags, still no luck

Try
            Dim MailClient As SmtpClient = New SmtpClient("111.11.111.111")
            MailClient.UseDefaultCredentials = False
            MailClient.Credentials = New Net.NetworkCredential("databaseID", "password")
            MailClient.EnableSsl = True
            Dim Mailmsg As New MailMessage

            Mailmsg.To.Clear()

            Mailmsg.To.Add(New MailAddress("[email protected]"))
            Mailmsg.From = New MailAddress(userEmail)
            Mailmsg.Subject =  SubjectS
            Mailmsg.Body = MessageS
            Mailmsg.IsBodyHtml = True
            MailClient.Send(Mailmsg)
        Catch ex As Exception
            myErrorL.Text = "<div class='alert alert-danger' role='alert'>Unable to send an email. " & ex.Message & "</div>"
            Return
        End Try


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1