0

My Project need to send an e-mail but I cannot send it. I don't know why. Last month I can send but today I cannot.

string url = Request.Url.AbsoluteUri;
string hyperlink = "<a href='" + url + "'>" + url + "</a>";
NetworkCredential loginInfo = new NetworkCredential("***examplemail***", "myPassword");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("***examplemail***");
msg.To.Add(new MailAddress("***ToEmail***"));
msg.Bcc.Add(new MailAddress("***examplemail***"));
msg.Subject = "TEST";
msg.Body = "Hi, TEST Send E-mail";
msg.IsBodyHtml = false;
SmtpClient client = new SmtpClient("smtp.gmail.com", 995); // tried 25 587 and 995
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);

** It didn't have any error but I didn't send too.

MethodMan
  • 18,625
  • 6
  • 34
  • 52

2 Answers2

0

I wouldn't use the port number in here.

SmtpClient client = new SmtpClient("smtp.gmail.com", 995); // tried 25 587 and 995

This way it sends. I tried and it worked. I am saying that it should look like

SmtpClient client = new SmtpClient("smtp.gmail.com");

If you check SmtpClient's constructor while writing the code you will see that it has one overload.

Cengiz Araz
  • 680
  • 9
  • 17
-1

Try this:

using System.Net;
using System.Net.Mail;

namespace consSendMail
{
    class Program
    {
        static void Main(string[] args)
        {
            SmtpClient smtpClient = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                Credentials = new NetworkCredential("yourmail", "yourpassword")
            };

            var mailMessage = new MailMessage();
            mailMessage.Subject = "Subject";
            mailMessage.From = new MailAddress("yourmail", "yourname");
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = "your message";            
            mailMessage.To.Add( new MailAddress("destinationemail") );

            smtpClient.Send(mailMessage);

            mailMessage.Dispose();
            smtpClient.Dispose();
        }
    }
}
Andre Mesquita
  • 879
  • 12
  • 25