Solved

Issue with SmtpClient in sending GMAIL Message

Posted on 2014-04-23
3
444 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
  • 2
3 Comments
 
LVL 78

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
There are many add-ons for Google docs, slides and sheets that can be extremely helpful in keeping your files organized and simple to use. Add-ons are installed into your Google docs, slides or sheets through Google's Add-On Store. One of my favorit…
By using UNIQUE function in Google Sheets, you can get around removing duplicates like in Microsoft Excel.
This Micro Tutorial will demonstrate how marketers can use the Mobile Emulation Tool in Chrome Developer Tool. This will let you preview your site on any mobile device.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now