Search code examples
c#gmail

Send email from c#


I installed on a server windows server 2008 service SmarterMail. Configured interface and works perfectly. I created a software in .net c # here's the code:

           MailMessage mail = new MailMessage();
            mail.From = new MailAddress("[email protected]", "Prova");
            foreach (string recips in email)
            {
                mail.To.Add(recips);
            }
            mail.Subject = "PRova";
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml = true;
            mail.Body = messaggio;
            foreach (string itemurl in file)
            {
                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment(itemurl);
                mail.Attachments.Add(attachment);
            }
            SmtpClient smtp = new SmtpClient(server);
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new NetworkCredential("prova", "prova");
            smtp.Send(mail);

The problem is when I send email to an address @ gmail.com. The emails come in all domains except for gmail. What can be the reason?


Solution

  • If the email works in all domains accept gmail. I would check if you have been black listed by gmail.

    This doesn't seem like a issue with code.

    That message tells you that you've basically have been blocked. I'd suggest not to focus on your code but to focus on what google's response is to you being blocked.