-1

I couldn't send mail using smtp ASPMX.L.GOOGLE.COM. I have domain domain.co.in and email address test@domain.co.in which is accessible in gmail. i Could send mail manually but not programmatically. throws below error. Service not available, closing transmission channel. The server response was: 4.7.0 [61.16.142.134 15] Our system has detected that this message is

MailAddress ma_from = new MailAddress("test@domain.co.in", "fromName");
        MailAddress ma_to = new MailAddress("jrao.XXXX@gmail.com", "fromName");
        string s_password = "TestPwd";
        string s_subject = "Test";
        string s_body = "This is a Test";
        SmtpClient smtp = new SmtpClient
        {
            Host = "ASPMX.L.GOOGLE.COM",
            Port = 25,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
           Credentials = new NetworkCredential(ma_from.Address, s_password)
        };
        using (MailMessage mail = new MailMessage(ma_from, ma_to)
        {
            Subject = s_subject,
            Body = s_body
        })
            smtp.Send(mail);

2 Answers2

0
  1. Where did you get those settings? I don't think port 25 will work with SSL. Try port 587 and host "smtp.gmail.com"

  2. The full response from Google would help. Was it perhaps "Our system has detected an unusual rate of unsolicited mail originating from your IP address. To protect our users from spam, mail sent from your IP address has been temporarily rate limited." Note that unless you're using a fixed-line internet connection from home, you're probably sharing an IP address with many other users.

  3. Ensure you have a "strong" password

  4. Ensure the "from" email address is your primary email address and not an alias.

Edward D
  • 521
  • 3
  • 9
  • if i use that smtp.gmail.com with port 587, its throws below error The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at – Jagadeeswararo Dec 30 '16 at 03:20
  • remember I used different domain ex:user@test.co.in which is worked for login and sending mails manually using gmail but not programmatically. – Jagadeeswararo Dec 30 '16 at 03:27
  • I've tested your code with smtp.gmail.com and port 587, sending as my vanilla gmail account, and it works for me. So the problem must be with your email address and/or password. Do you have a Google Apps (aka G Suite) user set up with the sending address's email? – Edward D Dec 31 '16 at 11:47
  • (I don't know what you mean by "used different domain". The email address in **ma_from** must be the same as the email address you use to log into GMail) – Edward D Dec 31 '16 at 11:51
  • OK, it sounds like if you have a "weak" password (short, without enough capital letters, numbers, or punctuation), GMail will still let you log in and everything but won't let you send mail via SMTP. Try logging into G Suite and changing your password. – Edward D Dec 31 '16 at 11:56
0

Try Using Port 587 And host "smtp.gmail.com"

Specially You'll need to set your gmail account allow less secure apps to send mails. It's a security concern in gmail.

You can set this setting by folowing this link. Allow Less Secure Apps

Hope this would help.. :)

Gayan Kavirathne
  • 2,909
  • 2
  • 18
  • 26