.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Sending email via SmtpClient() not working with smtp.gmail.com :(

Posted By:      Posted Date: September 11, 2010    Points: 0   Category :.NET Framework
Help I cannot seem to send an email via my gmail account using "C#" why not?   <system.net> <mailSettings> <smtp deliveryMethod="Network" from="ian.coetzer@gmail.com"> <network host="smtp.gmail.com" port="587" enableSsl ="true" defaultCredentials ="false" password ="xxxxxx" userName ="ian.coetzer@gmail.com"></network> </smtp> </mailSettings> </system.net> SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try { message.To.Add(emailTo); message.Subject = ""; message.Body = GetEmailBody(userName, password, url); smtpClient.Send(message); return true; } catch(Exception ex) { throw new ApplicationException("Could not send notification.", ex); }   I.W Coetzer

View Complete Post

More Related Resource Links

What will be the correct smtp settings for sending out email from an asp.net website to gmail's bus

Hi,I have setup a gmail's business account for my company.Now I want to receive all the emails like ContactUs, Qoute Email, etc from my website to that account i.e. info@mydomainname.com I have added the following smtp settings behind my web formsSmtpClient smtpClient = new SmtpClient("localhost",25); //Providing Network credentials smtpClient.Credentials = new System.Net.NetworkCredential("quote@mydomainname.com", "password"); smtpClient.UseDefaultCredentials = true; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; MailMessage mail = new MailMessage(); //HTML Mail Format mail.IsBodyHtml = false; //Setting Form , To and CC mail.From = new MailAddress("quote@mydomainname.com", "My Web Site"); mail.To.Add(new MailAddress("info@mydomainname.com")); This code gives me feedback "email has successful sent"  but it does not send any email to info@mydomainname.comCan anyone let me know what will be the correct smtp settings for sending out emails to gmail's business accounts?Regards,Dazy

smtp is noe sending email instantly,it makes a Queue in my local system

I am using a  smtp to send email from asp.net (C#)code.it sending some email instantly but many of email is making a queue in my Inetpub folder at local system.what could be the issue ? please help me to get rid from it.ThankxArvind

sending email using IIS smtp service


 I am working on an email that someone will send from one of our main sites requesting an account password.  I am using System.Net.Mail.MailMessage to create the email and then sending it using System.Net.Mail.SmtpClient.  Below is my code: 

	Public Function sendEmail(ByVal address As String) As String
		Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
		mailMessage.To.Add(New System.Net.Mail.MailAddress("emailAddress"))
		mailMessage.From = (New System.Net.Mail.MailAddress(address))
		Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
		Catch ex As Exception
			Throw New ApplicationException("Data Error", ex)
		End Try
	End Function

	Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
	End Sub

Then in my web.config file I have the following

				<network host="cook.CMAP.public" port="25" 
It all looks like it is right bu

smtp sending email twice.


I am using .net membership functionality, The problem is on forget password page it send two emails to the user , any idea why?

I am using Windows 2008 Server.

Imports System.Net.Mail

Partial Class registration_ForgotPassword
    Inherits System.Web.UI.Page
    Protected Sub btnSendPassword_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSendPassword.Click
    End Sub

#Region "SendForgotPasswordEmail"
    Private Sub SendForgotPasswordEmail()
        Dim emailFrom As String = ConfigurationManager.AppSettings("EmailFrom").ToString()

        Dim message As String = String.Empty
        Dim emailTo As String = txtEmail.Text

        Dim username As String
        Dim password As String
        password = ""

        Dim list As MembershipUserCollection
        list = Membership.FindUsersByEmail(emailTo)

        If list.Count > 0 Then
            username = Membership.GetUserNameByEmail(emailTo)
            password = list(username).ResetPassword()

            Dim msg As String = ""
            msg = "Your password is " + password

            msg = msg & "</br> As this is a temporary password please immediately change your password after login."
            message = msg
            Dim objmm As New MailMessag

Using WCF Service to Email with smtp.gmail


I am using silverlight 4 and I have implemented a WCF service to email my gmail account through the app.

My smtp.Send(msg) line is failing and sending it into the catch statement.

I'm not sure where the problem is but posted below is my code for the WCF service method it is failing in.

public bool SendMail(string emailTo, string emailFrom, string msgSubject, string msgBody)
            bool success = false;
                MailMessage msg = new MailMessage();

Sending a File Using Email Helper in WebPages/Razor


Note: This is particularly with respect to Email Helper in WebPages/Razor. Please don't post links using System.Net.Mail object.

Following this tutorial: http://www.asp.net/webmatrix/tutorials/9-adding-email-to-your-website

Under "Sending a File Using Email" section what exactly is the code trying to do.

1: The SendFile.cshtml does not have any option to select file.

2: ProcessFile.cshtml is running fine. I am getting the email but no attachement.

I tried changing fileAttachment input to type="file" but not file is being sent to my email. I just get the message send in body.

Question: How exactly this file attachment works using Email Helper in WebPages.

SMTP not working if I use web deployment package to deploy my app.


Hi all

I use msdeploy to install my web app. deployment package. everything about web app works, but find out email was not working.

I checked telnet smtp is running.

I debug the project, and it was sending out email too.

So my solution was upload the whole project (not complied) to wwwroot, and email works too. Thats why I assume the deployment cause the problem.

at last, I also tried to copy the web deployment web.config to replace the project's web.config, and the email also work, so it wasn't the web.config problem.

Could anyone tell me whats going on?

My environment:

window 2003

iis 6

.net framework 4.0

I cannot send mail using gmail smtp server


 Here is my code

Dim message As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
        message.To.Add("from textbox field")
        message.Subject = "Testing"
        message.From = New System.Net.Mail.MailAddress("sender email ")
        message.Body = "Just Testing"

        Dim smtp As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()

        Dim client As SmtpClient = New SmtpClient()
        smtp.Credentials = New System.Net.NetworkCredential("username", "password")
        smtp.Port = 25
        smtp.Host = "smtp.gmail.com"
        smtp.EnableSsl = True
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network
        lblmsg.Text = "Your Email has send"


getting a email delivert status when sending email using msdb.dbo.sp_send_dbmail


Hi All,

Can some help me regarding following.

I have set a job in sql server 2008 to send reminder emails for product expiration.
Now I want a report which will specify the list of the emails sent with the email status details like queued ,sent,delivered, failed.

I can fetch the emails that are sent by querying the like following

select * from sysmail_mailitems SM inner join sysmail_profile SP on SM.Profile_Id = SP.Profile_Id
and SP.Name ='ReminderProfile'

The problem is only getting a perfect status of email whether it is delived or failed. How I can get those status ?
Please help.


Email this Post in SharePoint Blog is not working for Lotus Notes 6.5


I have tried "Email this Post" in a SharePoint blog. I got the email as desired, but the doesnot resolve the post.

Here are the link examples:

I got the link in email as mentioned below:


But i should get as below to resolve the link:


Any ideas?


send email using Godaddy server by gmail


 Hello ,


My site is hosted  in Godaddy server. And i am using google apps for emailing a/c for that i have changed the  MX-records and then it is working fine.

Then i finished my web site


it is working fine there .

in the site there is a  contactus link which opens


this page basically should send a mail to a particular email id .

for sending mail I am using gmail a/c . (Here is the full code)


public void SendEmail(string From,string GmailEmail, string GmailPassword, string To, string Subject, string Body,      
        FileUpload fileupload)

        System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        mail.From = new MailAddress(From, "One Ghost", System.Text.Encoding.UTF8);
        mail.Subject = Subject;
        mail.SubjectEncoding = System.Text.Encoding.UTF8;

smtp server 5.1 in xp not sending emails


hi iam using asp.net 2.0 with c#.net.

in my application when client completes its shopping email will goes to user this works fine when there is internet connection is working fine,
if  there is some problem  in internet connection if one mail stops then all the mails will be stopped even now internet works fine,

how to resend the emails using smtp server, is there any option to resend the emails automatically when internet works fine.

can you give example which helps me.

sending an email in asp.net


My problem is  when i am writing the whole code in asp.net using vb which is

Protected Sub btnsend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsend.Click
        Dim mailmessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
        mailmessage.From = New System.Net.Mail.MailAddress(txtfromaddress.Text.Trim())
        mailmessage.To.Add(New System.Net.Mail.MailAddress(txtToAddress.Text.Trim()))
        mailmessage.Subject = txtSubject.Text.Trim()
        mailmessage.Body = txtbody.Text.Trim()
        Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()

In the last line i m getting smtpException unhandled by user code (Failure sending mail)

In the web.config file i have written the code which is as follows:-

      <smtp from="someaddress@myCTdomain.com">
        <network host

Error While sending Email using Outlook object in asp.net 4.0


Hi ,

            I am trying to send Email using Outlook object but  it gives following error :

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

I have added outlook reference "using Microsoft.Office.Interop.Outlook"  version

and i am using below code :

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook._NameSpace oNameSpace = oApp.GetNamespace("MAPI");
            Microsoft.Office.Interop.Outlook.MAPIFolder oOutboxFolder =
            oNameSpace.Logon(null, null, false, false);
            Microsoft.Office.Interop.Outlook._MailItem oMailItem =

Sending Email by exeucting a stored proc on SQL Server that references CLR

Hi Guys, I want to modify the data type of the @body variable in the stored procedure that sends an email. The stored procedure is as follows:   CREATE PROCEDURE [dbo].[spSendMail4]<br/> @recipients [nvarchar](4000),<br/> @cc [nvarchar](4000),<br/> @subject [nvarchar](4000),<br/> @from [nvarchar](4000), @body [nvarchar](4000), @attachment [nvarchar](4000)<br/> WITH EXECUTE AS CALLER<br/> AS <br/> EXTERNAL NAME [SMTPCLR].[StoredProcedure].[spSendMail]<br/> GO   I want to change the @body variable to data type: text. The reason for this, is because I am sending an HTML email whose content (characters) exceed 8000. Basically the new stored procedure should looks like below:   CREATE PROCEDURE [dbo].[spSendMail4] @recipients [nvarchar](4000), @cc [nvarchar](4000), @subject [nvarchar](4000), @from [nvarchar](4000), @body text, @attachment [nvarchar](4000) WITH EXECUTE AS CALLER AS EXTERNAL NAME [SMTPCLR].[StoredProcedure].[spSendMail] GO   If attempt to make this change, I get the below error:   CREATE PROCEDURE for "spSendMail" failed because T-SQL and CLR types for parameter "@body" do not match.   Understandably so, because from the article http://msdn.microsoft.com/en-us/library/ms131092%28SQL.100%29.aspx CLR data type (.NET Framework) is not compa

Email Sending Failed

I have email sending option in my ASP.net application(Developed in visual web developer2008 on XP), i am sending the mails with 3 attachements without any problems.I have launched same project in another branch(On windowsXP Machine), from here i am not succeeded to send mails.Following error was througing..My smtp server is smtp.mailserver.com. Server Error in '/' Application.--------------------------------------------------------------------------------No connection could be made because the target machine actively refused it Code Sending mail successfully from my local machineProtected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click        Dim smtp As New System.Net.Mail.SmtpClient()        Dim smail As New System.Net.Mail.MailMessage        lblMessage.Text = ""        If DDReceiver.Text = "" Then            MsgBox("Enter Valid E-Mail Address")        Else            smail.To.Add(New System.Net.Mail.MailAddress(DDReceiver.Text))        End If     

C# , Sending email through exchange server?

I've searched on this and tried several methods using System.Net.Mail but I can't get it to work. I want to send email using the Exchange server they have at work. Anyone could show me how to do this (server requires authentication)   Thanks in advance
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend