Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I have created a mail box. It doesn't work. Please can some one tell me why is that?

I created this by watching a video. i don't know i gave his port numbers and all. Is it okay or do i want change it and how can i do that?

It shows me an error message like this

**Error Message**

Server Error in '/' Application.

The remote name could not be resolved: 'smpt.gmail.com'

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.WebException: The remote name could not be resolved: 'smpt.gmail.com'

Source Error: 

Line 66:             //pass account information to the sender
Line 67:             tsmtpClient.Credentials = new System.Net.NetworkCredential("kasuniscg8@gmail.com", "kasuchin321");
Line 68:             tsmtpClient.Send(tmailmessage);
Line 69: 
Line 70: 

Source File: c:\Users\A\Desktop\Food new one\Backup\11-21\Food Calorie Calculator- Final Project\Food Calorie Calculator- Final Project\Admin\MailBox.aspx.cs    Line: 68 

Stack Trace: 


[WebException: The remote name could not be resolved: 'smpt.gmail.com']
   System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) +6646520
   System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) +307
   System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +19
   System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +324
   System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +141
   System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170
   System.Net.Mail.SmtpClient.GetConnection() +44
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1554

[SmtpException: Failure sending mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1906
   Food_Calorie_Calculator__Final_Project.Admin.MailBox.SenEmail(String from, String to, String cc, String bcc, String subject, String body, Boolean IsHTML) in c:\Users\A\Desktop\Food new one\Backup\11-21\Food Calorie Calculator- Final Project\Food Calorie Calculator- Final Project\Admin\MailBox.aspx.cs:68
   Food_Calorie_Calculator__Final_Project.Admin.MailBox.btn_Send_Click(Object sender, EventArgs e) in c:\Users\A\Desktop\Food new one\Backup\11-21\Food Calorie Calculator- Final Project\Food Calorie Calculator- Final Project\Admin\MailBox.aspx.cs:29
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628114
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724


What I have tried:

**aspx.cs** 
public partial class MailBox : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //Click event: send button
        protected void btn_Send_Click(object sender, EventArgs e)
        {
            string _from = "foodcaloriecalculator@gmail.com";
            string _to = txt_to.Text.Trim();
            string _cc = txt_cc.Text.Trim();
            string _bcc = txt_bcc.Text.Trim();
            string _subject = txt_sub.Text.Trim();
            string _body = txt_body.Text.Trim();

            //calling method
            SenEmail(_from,_to, _cc, _bcc, _subject, _body,true);
        }

        private static void SenEmail(string from,string to,string cc, string bcc, string subject,string body,bool IsHTML)
        {
            //create an instant in mail message
            MailMessage tmailmessage = new MailMessage();
            //assign sender mail address
            tmailmessage.From = new MailAddress(from);
            //asssign recipiant email address
            tmailmessage.To.Add(new MailAddress(to));
            //check if cc/bcc is not null
            if (cc != null && cc != "")
                tmailmessage.CC.Add(new MailAddress(cc));
            if (bcc != null && bcc != "")
                tmailmessage.Bcc.Add(new MailAddress(bcc));
            //assign the subject
            tmailmessage.Subject = subject;
            //assign the mail body
            tmailmessage.Body = body;
            //assign the format into mail box
            tmailmessage.IsBodyHtml = IsHTML;
            //assign the prority of the mail into normal
            tmailmessage.Priority = MailPriority.Normal;
            //subject encoding by UTF-8
            tmailmessage.SubjectEncoding = System.Text.Encoding.UTF8;
            //body encoding by UTF-8
            tmailmessage.BodyEncoding = System.Text.Encoding.UTF8;

            //Create a new instance of SMTP client and pass name port number from SMPT gmail server
            SmtpClient tsmtpClient = new SmtpClient("smpt.gmail.com", 587);
            //enable SSL of theamtp client
            tsmtpClient.EnableSsl = true;
            //use delivery method as network
            tsmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            //use the Credentials set to false
            tsmtpClient.UseDefaultCredentials = false;
            //pass account information to the sender
            tsmtpClient.Credentials = new System.Net.NetworkCredential("foodcaculator@gmail.com", "kachin321");
            tsmtpClient.Send(tmailmessage);
}
}
Posted
Updated 22-Nov-17 9:19am
v2
Comments
Bryian Tan 22-Nov-17 15:13pm    
smpt or smtp?
F-ES Sitecore 22-Nov-17 17:28pm    
smpt? foodcaculator? If you're not able to use google to find out how things are spelled then programming is probably going to be beyond you.

1 solution

I'm pretty sure the server you gave the code isn't correct:
smpt.gmail.com

Do you see a problem with that name?
 
Share this answer
 
Comments
phil.o 22-Nov-17 15:38pm    
Well spotted! My 5 :)

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