Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I need smpt server for gmail kindly provide me the code in asp
Posted
Comments
manoharnch 28-Dec-11 4:15am    
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="contactus.aspx.cs" Inherits="contactus" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Height="22px" Text="Label" Width="51px">Name
<asp:TextBox ID="to" runat="server"><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />


VB
Dim mail As New MailMessage()
mail.Add(to)
mail.From = New MailAddress(from)
mail.Subject = subject
mail.Body = body
mail.IsBodyHtml = True
Dim smtp As New SmtpClient("smtp.gmail.com", 587)
smtp.EnableSsl = True
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential(address, password)
smtp.Send(mail)
 
Share this answer
 
 
Share this answer
 
Hi,

Try this:
C#
MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587); // add port 587 or port 465
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(address, password);
smtp.Send(mail);


and see this link for further info...
VB
Gmail as a free smtp server



Regards,
 
Share this answer
 
v3
Comments
manoharnch 28-Dec-11 4:08am    
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

public partial class contactus : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from);
mail.Subject = "subject";
mail.Body = "hi how are you";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); // add port 587
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("manohar.nch@gmail.com", "000999");
smtp.Send(mail);
}
}

please update this one
Al Moje 28-Dec-11 4:24am    
Do you have a Gmail acount?
Please see link above: 'GMail as free smtp server'
Al Moje 28-Dec-11 4:50am    
if you have a GMail account and the setting is correct then try this:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class contactus : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); // add port 587
smtp.Credentials = new System.Net.NetworkCredential("manohar.nch@gmail.com", "000999");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
mail.Priority = MailPriority.High;
mail.From = new MailAddress("manohar.nch@gmail.com");
mail.Subject = "subject";
mail.Body = "hi how are you";
mail.IsBodyHtml = true;
mail.To.Add("manohar.nch@gmail.com");
smtp.Send(mail);
}
}
Al Moje 28-Dec-11 4:51am    
Vote on this if could help...
Regards,
Al Moje 28-Dec-11 5:04am    
forgot to add timeout:

smtp.Timeout = 300; // 300 seconds to wait so that could not catch timeout
smtp.Send(mail);
Use the below code.

MailMessage oMsg = new MailMessage();
                oMsg.From = new MailAddress("securuslistner@gmail.com", "Securus Listner");
                oMsg.To.Add(new MailAddress("rajeshcragy@gmail.com", "Securus Listner"));
                oMsg.Subject = "Packet Parsing Problem";
                oMsg.Body = " Problem Occuread test mail";
                oMsg.SubjectEncoding = System.Text.Encoding.UTF8;
                oMsg.BodyEncoding = System.Text.Encoding.UTF8;
                oMsg.IsBodyHtml = false;
                oMsg.Priority = MailPriority.High;

                SmtpClient oSmtp = new SmtpClient("smtp.gmail.com", 587);
                oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                oSmtp.EnableSsl = true;

                NetworkCredential oCredential = new NetworkCredential("securuslistner@gmail.com", "<password>");
                oSmtp.UseDefaultCredentials = false;
                oSmtp.Credentials = oCredential;
                oSmtp.Send(oMsg);</password>


Thanks
 
Share this answer
 
Please kindly current this



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

public partial class contactus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(to);
        mail.From = new MailAddress(from);
        mail.Subject = "subject";
        mail.Body = "hi how are you";
        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); // add port 587
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = new System.Net.NetworkCredential("manohar.nch@gmail.com", "000999");
        smtp.Send(mail);
    }
}



error:
VB
Error   1   A using namespace directive can only be applied to namespaces; 'System.Net.Mail.MailMessage' is a type not a namespace  F:\web sites\help php\contactus.aspx.cs 13  7   F:\web sites\help php\
 
Share this answer
 
v4
Comments
manoharnch 28-Dec-11 4:12am    
still it is not working sravani garu
Add
using System.Net;
using System.Net.Mail;
C#
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com");
MailMessage message = new MailMessage("your's e-mail id(xyz@gmail.com)","e-mail id of the person you want to send mail" );
message.Body = "Body";
message.Subject = "Subject";
client.Credentials = new System.Net.NetworkCredential("Your gmail login(xyz)", "gmail password");
client.Port = Convert.ToInt32("587");
client.Send(message);
MessageBox.Show("Mail delivered successfully!!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Message could not be sent.\nThe following error was returned:\n’" + ex.Message + "‘", "Sending Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

this is working perfectly on my system.
 
Share this answer
 
You can try following link,

Send mail using Google Apps[^]

Hope this may help you!
 
Share this answer
 
 
Share this answer
 

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