?
Solved

Issue with SmtpClient in sending GMAIL Message

Posted on 2014-04-23
3
Medium Priority
?
462 Views
Last Modified: 2014-11-12
Hello Experts,

I am trying to send Message from my GMAIL account via C# code.

I could able to send it via classic methos i.e. by using 'System.Web.Mail.SmtpMail.Send(Mail)'. Find the attachement - "Working-Copy.JPG".

But I couldn't able to send GMAIL message from C# code by using System.Net.Mail.SmtpClient'.

I tried with two ways:

1) By Routine Procedure. Find the attachment - "TriedWithThisToo.JPG".

2) By using OpenPOP3 API. Find the attachment - "OpenPop3.JPG".

I want to send GMAIL message by using SmtpClient only for my project.

Any help would be grateful.

Cheers
Working-Copy.JPG
TriedWithThisToo.JPG
OpenPop3.JPG
0
Comment
Question by:Md Shah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 total points
ID: 40017978
Are you referring to OpenPop.NET 2.0.5 as found on sourceforge?

Why don't you just use the working code as you don't need POP3 just SMTP?
using System;
using System.Linq;
using System.Net;
using System.Net.Mail;

namespace pop3test_ee
{    class Program
    {
       static void Main(string[] args)
        {
            var t = new MySend();
            t.test1();
            Console.ReadKey();

        }
    }
    class MySend
    {
        public void test1()
        {
            try
            {
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.EnableSsl = true;
                client.Timeout = 100000;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential("nobody@gmail.com", "password");
                MailMessage msg = new MailMessage("From Address<nobody@gmail.com>", "To Address <nobody@techsupport4me.com>", "Test Subject With Names", "Test Body With Names");
                client.Send(msg);
                System.Console.WriteLine("Successfully Sent Message");
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
    }
}

Open in new window

0
 
LVL 8

Author Comment

by:Md Shah
ID: 40018259
Thanks David your code has worked too.

But the main issue why i am opting to go for OpenPop3 API is...

In my project, I need to read new messages from client and need to REPLY to client message with ATTACHMENT.

Please let me know if I can achieve REPLY TO and ATTACHMENT with your above code
0
 
LVL 8

Author Closing Comment

by:Md Shah
ID: 40020271
Thanks
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial demonstrates how to create custom reports and the secrets of determine the metrics and dimensions for your data that works best with your needs.
This Micro Tutorial will demonstrate using Google Doc how to import live data to another spreadsheet in Google Spreadsheets using the IMPORTRANGE function.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question