Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello...

I am working on the project of INTRANET MAILING SYSTEM but while sending the mail my mail messages are getting stuck in the QUEUE rather going to the MAILBOX.

Actually I am using my system only as the server i.e. localhost for sending and receiving the mail messages.

And 1 more thing I would like to ask that what would be my domain name just like qaz@gmail.com, then what should I write instead of GMAIL in the addressee part of the mail?

Do I need to install any external server or anything like that?

Can you suggest me how to sort out this problem!!!
Posted

You need to have an SMTP server setup and configured. From there you can use the server's address/port, by then you should also have a registered mail domain.
 
Share this answer
 
As Mark said, you need a working SMTP server, whether it is for an intranet or the internet.

Get this working first and test with a normal email client like Outlook or Thunderbird.

When this is working, it should be a trivial task to use the System.Net.Mail namespace to send your email.

Nick
 
Share this answer
 
I did a similar thing for my final year project.
I had a table in my database with all the users' email addresses, and another one with the set messages i wanted to display eg: "Your order number is :" and i would insert the order number from my app.
I used a stringbuilder so that the email would be written as one sentence. You can manipulate it however you want.
So, in my view layer, i had the following code in the user registration page (since an email is sent to confirm the registration:

using System.Net;
using System.Net.Mail;

public void CreateUser()
{
//BC_GmailSender is the method in my business layer

StringBuilder message = new StringBuilder();
message.Append(BC_GmailSender.GetMessage(13)); //The message that says "you have successfully registered"
message.AppendLine(BC_GmailSender.GetMessage(8) + " " + cust_id); //"Username"
message.AppendLine(BC_GmailSender.GetMessage(9) + " " + password); //"Password"

NetworkCredential loginInfo = new NetworkCredential("your_email@gmail.com", "your_password");
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("your_email@gmail.com");
            msg.To.Add(new MailAddress(email)); //The email address that the customer entered, a string
            msg.Subject = "Whatever subject";
            msg.Body = message.ToString();
            msg.IsBodyHtml = true;

            //Every email needs an smtp client
            //To use the Gmail smtp client:
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);
}
 
Share this answer
 
v2
Sending email from a web page is one of the most common functionality required from a web site.

The System.Web.Mail Namespace in the .NET Framework contains the required support classes and enumerations for email capabilities.

The main classes used are System.Web.Mail.MailMessage and the SmtpMail class.

Listing1 contains the listing for a simple web form to send email. This form assumes that the SMTP service is running on the server.

Listing 1: Send an email from ASP.Net Page.

ASP.NET
<%@ Import Namespace="System.Web.Mail" %>
<script language="c#"  runat="server">

private void btnSend_Click(object sender, System.EventArgs e)

{                                                

    MailMessage msg = new MailMessage();
 

    msg.To = txtTo.Text;

    msg.From = txtFrom.Text;

    msg.Subject = txtSubject.Text;

    msg.Body = txtContent.Value;
    lblStatus.Text = "Sending...";
                                             

    SmtpMail.Send(msg);

    lblStatus.Text = "Sent email (" + txtSubject.Text + ") to " +txtTo.Text;                                         

}

</script> 

<html>

<body>

    <h3>

        Email From ASP.NET</h3>

    <form id="MailForm" method="post"  runat="server">

        <asp:Label ID="Label1" Style="left: 100px; position: absolute; top: 100px" runat="server">From:   

        

        <asp:TextBox ID="txtFrom" Style="left: 200px; position: absolute; top: 100px"

          runat="server">

        <asp:RequiredFieldValidator ID="FromValidator1" Style="left: 100px; position: absolute;

            top: 375px" runat="server" ErrorMessage="Please Enter the Email From." Width="200px"

            Height="23px" ControlToValidate="txtFrom">

        <asp:RegularExpressionValidator ID="FromValidator2" Style="left: 100px; position: absolute;

            top: 400px" runat="server" ErrorMessage="Please Enter a Valid From Email address"

            ControlToValidate="txtFrom" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)

            *">

        <asp:Label ID="Label2" Style="left: 100px; position: absolute; top: 125px" runat="server">To: 

        

        <asp:TextBox ID="txtTo" Style="left: 200px; position: absolute; top: 125px"

          runat="server">

        <asp:RequiredFieldValidator ID="ToValidator1" Style="left: 100px; position: absolute;

            top: 425px" runat="server" ErrorMessage="Please Enter the Email To." Width="200px"

            Height="23px" ControlToValidate="txtTo">

        <asp:RegularExpressionValidator ID="ToValidator2" Style="left: 100px; position: absolute;

            top: 450px" runat="server" ErrorMessage="Please Enter a Valid To Email address"

            ControlToValidate="txtTo" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)

            *">

        <asp:Label ID="Label3" Style="left: 100px; position: absolute; top: 150px"

          runat="server">Subject

        <asp:TextBox ID="txtSubject" Style="left: 200px; position: absolute; top: 150px"

            runat="server">

        <asp:Label ID="Label4" Style="left: 100px; position: absolute; top: 175px" runat="server">Mail:

        

        <textarea  runat="server" id="txtContent" style="left: 200px; width: 400px; position: absolute;

            top: 175px; height: 125px" rows="7" cols="24">

                </textarea>

        <asp:Button ID="btnSend" Style="left: 200px; position: absolute; top: 350px" runat="server"

            Text="Send" OnClick="btnSend_Click">

        <asp:Label ID="lblStatus" Style="left: 250px; position: absolute; top: 350px" runat="server"> 

        

    </form>

</body>

</html>
 
Share this answer
 
v3

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