European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

European ASP.NET Hosting :: How to Connect MySQL Server with .NET in C# or ASP.NET

clock November 8, 2011 05:18 by author Scott

In this tutorial, I will show you how to connect to MySQL Server with .NET in C# or ASP.NET. What requirements do you need?

1. Please download
MySQL Connector/Net.
2. After you add a reference to your project, it is probably in C:\Program Files\MySQL\MySQL Connector Net 5.0.7\Binaries\.NET 2.0 folder, add the MySql.Data.dll file as a reference.
3. Make your connection string, the following code will shows a standard MySQL connection string

using MySql.Data.MySqlClient;
public static string GetConnectionString()
string connStr =
String.Format("server={0};user id={1}; password={2};
database=yourdb; pooling=false", "yourserver",
"youruser", "yourpass");

return connStr;

4. Then create an instance from MySql.Data.MySqlClient.MySqlConnection as shown below.

MySql.Data.MySqlClient.MySqlConnection mycon
= new MySqlConnection( GetConnectionString());

5. Then try to open the MySQL connection.

if(mycon .State != ConnectionState.Open)
mycon .Open();
catch (MySqlException ex)
throw (ex);

Simple right?? J

European ASP.NET 4.0 Hosting :: How to Send Email Using Gmail in ASP.NET

clock June 16, 2011 06:55 by author Scott

If you want to send email using your Gmail account or using Gmail's smtp server in ASP.NET application or if you don't have a working smtp server to send mails using your ASP.NET application or aspx page than sending e-mail using Gmail is best option.

You need to write code like this

First of all add below mentioned namespace in code behind of aspx page from which you want to send the mail.

using System.Net.Mail;

Now write this code in click event of button

C# code

protected void Button1_Click(object sender, EventArgs e)

  MailMessage mail = new MailMessage();
  mail.From = new MailAddress("");
  mail.Subject = "Email using Gmail";

  string Body = "Hi, this mail is to test sending mail"+
                "using Gmail in ASP.NET";
  mail.Body = Body;

  mail.IsBodyHtml = true;
  SmtpClient smtp = new SmtpClient();
  smtp.Host = ""; //Or Your SMTP Server Address
  smtp.Credentials = new System.Net.NetworkCredential
//Or your Smtp Email ID and Password
  smtp.EnableSsl = true;

VB.NET code

Imports System.Net.Mail

Protected  Sub Button1_Click
(ByVal sender As Object, ByVal e As EventArgs)
  Dim mail As MailMessage =  New MailMessage()
  mail.From = New MailAddress("")
  mail.Subject = "Email using Gmail"

  String Body = "Hi, this mail is to test sending mail"+
                "using Gmail in ASP.NET"
  mail.Body = Body

  mail.IsBodyHtml = True
  Dim smtp As SmtpClient =  New SmtpClient()
  smtp.Host = "" //Or Your SMTP Server Address
  smtp.Credentials = New System.Net.NetworkCredential
  smtp.EnableSsl = True
End Sub

You also need to enable POP by going to settings > Forwarding and POP in your gmail account

Change to your gmail ID and YourGmailPassword to Your password for Gmail account and test the code.

If your are getting error mentioned below
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."

than you need to check your Gmail username and password.

If you are behind proxy Server then you need to write below mentioned code in your web.config file


<proxy proxyaddress="YourProxyIpAddress"/>

If you are still having problems them try changing port number to 587

smtp.Host = ",587";

If you still having problems then try changing code as mentioned below

SmtpClient smtp = new SmtpClient();
smtp.Host = "";
smtp.Port = 587;
smtp.UseDefaultCredentials = False;
smtp.Credentials = new System.Net.NetworkCredential
smtp.EnableSsl = true;

Hope this help!!

About is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.

Tag cloud

Sign in