Solved

Issue with SmtpClient in sending GMAIL Message

Posted on 2014-04-23
3
458 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 81

Accepted Solution

by:
David Johnson, CD, MVP earned 500 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

The choice of selecting a perfect productive suite for one’s organization is a critical decision that an IT Manager or a CIO has to make. And when it comes to choosing a cloud-based productivity suite, the choice gets all the more difficult. This is…
Learn about cloud computing and its benefits for small business owners.
This Micro Tutorial  demonstrates whether your site uses one subdomain or multiple subdomains, how to create full URLs from Google Analytics content reports. This procedure is called concatenation and can also be done with the CONCATENTATE function.…
This Micro Tutorial will demonstrate Google Calendar to monitor updates with top sites, such as Facebook, Google, Twitter, etc. with Marketing News. Each update of Google Calendar can be monitored, correlate dips and spikes in your website traffic, …

705 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