ASP.NET - send and recieve mails - Asked By goldy gupta on 04-Feb-10 12:52 AM

I am making a new ASP.NET web application..

Here I wants to give user the facillity to send mails and recieve mails in my application..

I want this for gmail and hot mail..


what coding will be required for this..

 

Thanks in advance....

Venkat K replied to goldy gupta on 04-Feb-10 01:08 AM

Here is a nice small sample application to send an email:

http://www.codeproject.com/KB/aspnet/EmailApplication.aspx

If you want to restrict to only gmail and hotmail users then you can use a regular expression to validate the email address given in text box.

Validation the Gmail / Hotmail address:

1. We can use the following validation expression to ensure the email address is valid.

http://regexlib.com/Search.aspx?k=email&c=-1&m=-1&ps=20

2. Then you can use another expression to validate whether the email address is free.

^[.]?@(hotmail|gmail)[\w]+

If validation has pass, it proved to include 'hotmail','gmail' free email.

Thanks,

Sakshi a replied to goldy gupta on 04-Feb-10 01:30 AM

Complete set of coding that can be used directly below,

http://www.shabdar.org/send-email-using-gmail-account-asp-net-csharp.html

http://csharpdotnetfreak.blogspot.com/2009/06/aspnet-send-email-using-gmail.html

DL M replied to goldy gupta on 04-Feb-10 01:57 AM
Use this code sample to send and receive using Gmail account .

protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To.Add("jainamit.agra@gmail.com");
mail.To.Add("amit_jain_online@yahoo.com");
mail.From = new MailAddress("jainamit.agra@gmail.com");
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 = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("YourUserName@gmail.com","YourGmailPassword");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
}
http://csharpdotnetfreak.blogspot.com/2009/08/send-email-using-gmail-in-aspnet.html    http://csharpdotnetfreak.blogspot.com/2009/10/send-email-with-attachment-in-aspnet.html
http://www.aspcode.net/Send-mail-from-ASPNET-using-your-gmail-account.aspx

http://www.csharphelp.com/2007/04/access-hotmail-using-c/

Huggy Bear replied to goldy gupta on 04-Feb-10 02:07 AM
In order to send emails you should have a valid SMTP server for relaying the emails, that your application sends.
Also you should create a valid account for receiving emails.

Include the namespace System.Net.Mail in order to make use of the below function. Note that my comments are inlined

public void SendEmail(string smtpHost, string subject, string body, string fromId, string toId)
{
    string replyToId = "yourgmailid@gmail.com";
    MailMessage message = new MailMessage();
    message.Subject = subject;
    message.Body = body;
    //Set this in order to represent the email body as a HTML text and format accordingly
    message.IsBodyHtml = true;
    message.From = new MailAddress(fromId);
    message.To.Add(new MailAddress(toId));
    //This will the id which will be in the To list, when user clicks on reply in his mail box.
    //so properly configure it
    message.ReplyTo = new MailAddress(replyToId);

    SmtpClient client = new SmtpClient(smtpHost);
    client.Send(message);
}
mv ark replied to goldy gupta on 04-Feb-10 11:31 PM
Simple Mail Transfer Protocol (SMTP) server handles the sending of your email messages to the Internet while a Post Office Protocol 3 (POP3) server holds incoming email messages until you check your email.

This code snippet shows how you can send an email programmatically using C# with GMail - http://mvark.blogspot.com/2006/09/sending-mail-programmatically-using-c.html

Adapt the same code using the Hotmail credentials mentioned below to send an email programmatically with Hotmail

You can retrieve Mails from Gmail & Hotmail with POP3 component like Indy.Sockets:
http://www.codeproject.com/KB/IP/POP3ClientByChadZHower.aspx
http://www.indyproject.org/

Before you fetch mails from Gmail, you will have to enable POP access explicitly - http://mail.google.com/support/bin/answer.py?hl=en&answer=13273

These are the details to use:
Gmail -
pop.gmail.com
Use SSL: Yes
Port: 995

Hotmail -
pop3.live.com
Use SSL: Yes
Port: 995

SMTP server: smtp.live.com (Port 25) {Note: If port 25 has been blocked in your network or by your ISP, you can set SMTP port to 587 with TLS or SSL Encryption depending on the client in use}

Gmail provides free POP access -
http://mail.google.com/support/bin/answer.py?hl=en&answer=10350
http://mail.google.com/support/bin/answer.py?hl=en&answer=13273

Free POP3 feature in Windows Live Hotmail
http://windowslivehelp.com/solutions/settings/archive/2009/01/13/pop3-availability-in-windows-live-hotmail.aspx
http://techblissonline.com/hotmail-pop3-and-smtp-settings/
paul z replied to DL M on 04-Jul-11 03:39 PM
But I still cannot find out how to receive.

----------
http://www.emailembeddedimage.com/