0

I want to check sending emails locally. I use this code

If DT.Rows.Count > 0 Then
            Dim TmpEmail As String = DT.Rows(0).Item("email").ToString

            Dim mail As New MailMessage()
            Dim SmtpClient As New SmtpClient("webmail.namespace.net")

            mail.From = New MailAddress("mymail@mynamespace.net")

            mail.[To].Add(TmpEmail)
            mail.Subject = " subject" & Subject_EmailType_Max10Char
            mail.IsBodyHtml = True
            mail.Body = BodyHtml

            SmtpClient.Port = 25

            SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
            SmtpClient.UseDefaultCredentials = False
            SmtpClient.Credentials = New System.Net.NetworkCredential("mymail@mynamespace.net", "########password")
            SmtpClient.EnableSsl = True
            SmtpClient.Timeout = 200000
            SmtpClient.Send(mail)

when I send email to the same Domain of my network the email send successfully but when I send email to gmail the error MailBox unavailable. The server response was: 5.7.1 Unable to relay will appear when send email .When I send from my email (from outlook) to outside domain there is not problem. I use framework 4.5 visual studio 2012. I google for it and find solution like configured SMTP server but I don't want to install IIS6. I want to check it locally. Any idea?

I also use my gmail as mail.From and for SmtpClient.Credentials set my gmail and password and set SmtpClient.Port = 587 and Dim SmtpClient As New SmtpClient("smtp.gmail.com") and send email to gmail account the problem remain the same.The error is Failure sending mail..

Community
  • 1
  • 1
Question
  • 61
  • 11
  • That is a server configuration, the administrator of "webmail.comsec.gov.iq" should enable relay sending. You can do nothing to enable it client side in the c# code. – Cleptus Jan 23 '17 at 08:49
  • @bradbury9 but there is not problem when I send email from outlook to outside domain. the admin said relay sending is enabled. – Question Jan 23 '17 at 08:56
  • What I have experienced so far the relay message can raise if: a) You are not authenticated to the email server. Most servers allow relay only to **proper** authenticated requests. a) The email server does not allow relay. – Cleptus Jan 23 '17 at 08:59
  • @bradbury9 I use my gmail as `mail.From` and for `SmtpClient.Credentials` set my gmail and password and set `SmtpClient.Port = 587` and `Dim SmtpClient As New SmtpClient("smtp.gmail.com")` and send email to gmail account the problem remain the same.The error is **Failure sending mail.**. – Question Jan 23 '17 at 10:19
  • Gmail does not use port 25... Check this answer for actual Gmail SMTP parameters and sample code http://stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c-sharp – Cleptus Jan 23 '17 at 15:04
  • @bradbury9 yes I use port 587 as you see in the comment. – Question Jan 24 '17 at 04:59
  • In the link I provided yesterday there are several answers helping out different gmail related problems/misconfigurations and how to solve them. Maximum email limit, gmail captcha settings, enabling imap and/or pop, password strength, etc. – Cleptus Jan 24 '17 at 15:05
  • @bradbury9 Thanks, I try them and password was strong and I change it 2 or 3 times and all of them were. Finally it works! just by changing password in third time. – Question Jan 25 '17 at 07:09

1 Answers1

1

I tried several answers in question and I change password for 3 times and all of them were strong. Finally it works in third time of changing the password. I should mention that it doesn't work in my local host but it works when I publish it in the outside server(hosting).

Community
  • 1
  • 1
Question
  • 61
  • 11