473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

C# Email with gmail

270 100+
how to send instant e-mails using .net?
Apr 4 '09 #1
5 2958
NitinSawant
270 100+
I'm using fillowing code to send e-mail but it throws exception with message: Failure sending mail.

Expand|Select|Wrap|Line Numbers
  1. try{
  2.             String emailTitle ="My Email Title";
  3.             System.Net.Mail.MailMessage emailMessage;
  4.             String body = "This will appear in the body of my email";
  5.             emailMessage = new System.Net.Mail.MailMessage("nitin.sawant2008@gmail.com", "nitin_sawant89@rediffmail.com", emailTitle, body);
  6.             SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 25);
  7.             //25 is the port on which the mail server is listening.  If your mail server
  8.             //runs on the default port this number does not need to be provided
  9.  
  10.  
  11.             //If you do not need to provide credentials to connect to the mail server you can ignore the next 3 lines
  12.             //NetworkCredential myCredentials =NetworkCredential(System.Configuration.ConfigurationManager.AppSettings("EmailUserName"), System.Configuration.ConfigurationManager.AppSettings("EmailPassword"));
  13.             NetworkCredential myCredentials =new NetworkCredential("myusername","password");
  14.             mailClient.UseDefaultCredentials = false;
  15.             mailClient.Credentials = myCredentials;
  16.             mailClient.Send(emailMessage);
  17.             Label1.Text = "Sent";
  18.          }
  19.         catch(Exception ex)
  20.         {
  21.             Label1.Text = ex.Message + "";
  22.         }
  23.  
help me
someone post working code to send e-mail using gmail with .net 2.0
Apr 4 '09 #2
tlhintoq
3,525 Expert 2GB
@Nitin646
What do you mean by an "instant" email?
Apr 5 '09 #3
tlhintoq
3,525 Expert 2GB
Does gmail require SSL? I notice you have no setting for that
Expand|Select|Wrap|Line Numbers
  1.             myMailClient.EnableSsl = false;
  2.  
You might also want to try using port 587 instead of port 25. Maybe your ISP has port25 blocking turned on.

Otherwise everything you have there looks just like how I do it in my app. (not using gmail, though)

I would take all your working settings that succeed in Outlook for sending via gmail and make sure you have everyone accounted for and duplicated in code.
Apr 5 '09 #4
Plater
7,872 Expert 4TB
For GMAIL:
You need to log into gmail and enable smtp for the account you wish to use.
You need to use SSL
You need to use a special port
Apr 6 '09 #5
Hi Nitin646,
were you able to send mail using gmail? I am also facing the same problem while trying to send mail. I tried sending mail using IIS but all the message are getting stuck in the queue folder.
Any ideas/suggestions will be appreciated.
Thnx
Apr 9 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: D. Alvarado | last post by:
Hello, I have signed up a for a Google Gmail account. I sent myself some PHP-generated HTML emails from two different machines using this code: $to = "dave@gmail.com"; $id = 1234; $from =...
5
by: Das | last post by:
Hi, I'm trying to email html page & that page also contains the images. I can do that when we send html page from ms outlook. But I want to attach page c# code & send the mail through smtp mail....
26
by: libsfan01 | last post by:
Hi all! Can anyone show me how to check and email field on a form for the existence of these two characters. Kind regards Marc
16
by: =?Utf-8?B?Q2hlZg==?= | last post by:
I can use outlook2003 to send email,but I cann't use this code below to send email. Please help me to test this code and instruct me how to solve this problem in detail. software...
0
by: .spider | last post by:
Hi, I have a code here (taken from http://www.dotnetwatch.com/page294.aspx). Now i didn't think there was anything wrong with this code(no compilation errors..nothing)..and infact when i ran this...
15
by: Craig Hurley | last post by:
Hello, user@x.com receives an email from user@a.com. I want to forward that email to user@y.com. I want the contents/header to remain intact, with the exception of adding "X-Forwarded-For". ...
6
by: gnewsgroup | last post by:
I am using Peter Bromberg's code to send email through gmail smtp service in my asp.net web application. Thanks, Peter. The problem with gmail smtp is that gmail will overwrite the sender's...
45
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
14
by: Warren Tang | last post by:
Hi I am using the mail function to send a mail like this: $b = mail("my_real_email_address@gmail.com", "Hello from PHP", "Hi, finally sent an email successfully"); But it failed. Could you...
31
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.