Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
//these are namespaces i called
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Deployment;
using System.Threading;
using System.ComponentModel;

try
            {
                MailMessage mail = new MailMessage();
                //Setting From , To and CC
                mail.From = new MailAddress("info@wlcfoleh.com", "MyWeb Site");
                mail.To.Add(new MailAddress("eruoghene507@gmail.com"));
                mail.CC.Add(new MailAddress("MyEmailID@gmail.com"));
                mail.Body = msgtext.Text;

                SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);

                smtpClient.Credentials = new System.Net.NetworkCredential("eruoghene507@gmail.com", "this is fun");
                smtpClient.UseDefaultCredentials = true;
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.EnableSsl = false;

                smtpClient.Send(mail);
                Response.Write("Email Sent");
            }
            catch (Exception q)
            {
                Label12.Text = "Message: " + q.Message + "Source: " + q.Source + "Stack Trace: " + q.StackTrace;
            }
Posted
Updated 29-Sep-14 15:56pm
v2
Comments
[no name] 29-Sep-14 21:38pm    
The port for gmail is not 25. It's 587 or 465 depending on if you are trying SSL or not. And the default credentials should be false since you are supplying something other then the default.
Sergey Alexandrovich Kryukov 29-Sep-14 22:48pm    
Also, credential cannot be default.
—SA

Change the code to

C#
MailMessage mail = new MailMessage();
//Setting From , To and CC
mail.From = new MailAddress("MyEmailID@gmail.com", "MyWeb Site");
mail.To.Add(new MailAddress("eruoghene507@gmail.com"));
mail.CC.Add(new MailAddress("MyEmailID@gmail.com"));
mail.Body = msgtext.Text;
 
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; 
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = new System.Net.NetworkCredential("eruoghene507@gmail.com", "this is fun");
smtpClient.Send(mail);
Response.Write("Email Sent");


Hope the above changes help.
 
Share this answer
 
v2
Comments
EasyHero 30-Sep-14 3:14am    
I just tried the code and I get these errors as sent by the exception.message, exception.source
Message: Error in processing.
Source: System
and stack trace said I had an error at this line of code
smtpClient.Send(mail)
ChauhanAjay 30-Sep-14 3:24am    
I have moved this line smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; above
smtpClient.Credentials = new System.Net.NetworkCredential("eruoghene507@gmail.com", "this is fun");

Kindly check now as it has worked for me.
Please try like this it is working.am using same code.

MailMessage msf = new MailMessage("samatha507@gmail.com", "samatha507@gmail.com", "test mail", "no matter");               
                msf.IsBodyHtml = false;
                NetworkCredential ne = new NetworkCredential("samatha507@gmail.com", "mypassword");
                SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
                sc.UseDefaultCredentials = false;
                sc.Credentials = ne;
                sc.EnableSsl = true;
                sc.Send(msf);
                Response.Write("mail send successfully");
 
Share this answer
 
v2
Comments
EasyHero 30-Sep-14 16:24pm    
i still get this set of errors;
Message: Error in processing. The server response was: Request action aborted on MFE proxy, SMTP server is not available.
Source: System.
Stack Trace: at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) at WLCFoleh.contact.submitmsg_Click(Object sender, EventArgs e) in C:\Users\israel asha\Documents\Visual Studio 2010\Projects\WLCFoleh\WLCFoleh\contact.aspx.cs:line 55
line 55 being sc.Send(msf);
Samatha Reddy G 1-Oct-14 1:05am    
Check every thing smtp.gmail.com and port number. for me it is working , how you are writing once put your code , i will go through that.

once you take separate application and copy and paste same code , give your credentials execute it defnetly it will work
EasyHero 30-Sep-14 16:29pm    
can my location (nigeria) be a determining factor for this error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900