Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Issue with SmtpClient in sending GMAIL Message

Posted on 2014-04-23
3
Medium Priority
?
466 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 83

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Many of you may be aware of the recent Google Docs scam emails that have been floating around coming from various people that you know. Here's a guide on identifying How To Identify the Scam Email You will see an email from someone you’ve had co…
By using UNIQUE function in Google Sheets, you can get around removing duplicates like in Microsoft Excel.
This Micro Tutorial will demonstrate how to analyze your website's back links using a network graph powered by a fusion table.
Suggested Courses

609 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