Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi y'all,

I have an issue with a simple email client, the code works fine. However, the message is not delivered into Gmail/Hotmail inbox. I was wondering if I need to write the code into ASP.NET instead of WinForms project. Here's the code below, please advise.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Mail;


namespace Email_Client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            try
            {

                SmtpClient client = new SmtpClient();
                //client.Port = 25;
                client.Port = 465;
               // client.Host = "smtp.live.com";
                client.Host = "smtp.gmail.com";
                client.EnableSsl = true;
                client.Timeout = 100000;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.EnableSsl = true;
                client.Credentials = new System.Net.NetworkCredential("sener_email", "password");

                MailMessage mm = new MailMessage("sender_email", "recipient_email ", "Subject", "Body");
                mm.IsBodyHtml = true;
                mm.BodyEncoding = UTF8Encoding.UTF8;
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                client.Send(mm);
                label1.Text = "Message sent..";
            }
            catch (Exception e)
            {
                label1.Text = e.ToString();
            }

        }
               
    }
}



Thanks,

What I have tried:

I have tried to change the SMTP server between Gmail and Hotmail, but the results the same. No messages were received.
Posted
Updated 23-Oct-16 19:19pm
Comments
Truld 19-Apr-17 4:10am    
Try this C# class for SMTP client, also check this example that demonstrates how to send an email with C# or VB.NET code.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900