mail sending with asp.net,c#,webconfig.

sohil.shivani 0 Tallied Votes 475 Views Share

Hello sir,
I tried with this code it is running well but I am not getting mail in my account with this code, even this code is not giving any error.
Is there any problem??
Please help me.

SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["SMTP"], 25);
        //SmtpClient smtp = new SmtpClient("localhost");
        MailMessage message = new MailMessage();
        message.Subject = "Thank you for booking.";
        //message.To.Add(d.email);
        message.To.Add(new MailAddress("xxx@yyyy.com"));
        message.Body = "Body :  Start Date & Time: " + objBook.starttime + "<br> Customer Name: " + name + "</br><br> CustomerPhone:" + phone + "</br><br> CustomerAddress:" + address + "</br><br>  Source:" + source + "</br><br>  Destination:" + dest;
        message.From = new MailAddress("xxx@yyyy.com");
        message.IsBodyHtml = true;

        //smtp.Host = "localhost";
        try
        {
            smtp.Send(message);
        }
        catch (System.Exception e)
        {
            //TODO show message that driver email not valid or server problem
            MessageBox.Show(e.Message);
        }

        SmtpClient messagecust = new SmtpClient();

        MailMessage msgcust = new MailMessage();
        msgcust.Subject = "Thank you for booking.";
        msgcust.To.Add(objBook.objCust.email);
        msgcust.Body = "Start Date & Time: " + objBook.starttime + "<br> DriverName:'" + d.name + "</br><br> Driver PhoneNumber: " + d.phone + "</br><br> Driver Email-id: " + d.email;
        msgcust.From = new MailAddress("xxx@yyyy.com");
        msgcust.IsBodyHtml = true;

        messagecust.Host = ConfigurationManager.AppSettings["SMTP"];
        //messagecust.Host = "localhost";
        try
        {
            smtp.Send(msgcust);
        }
        catch (System.Exception e)
        {
            //TODO show message that customer email not valid or server problem
            MessageBox.Show(e.Message);
        }



////// web config code:


<system.net>
		<mailSettings>
			<smtp>
				<!--<network host="localhost"/>-->
				<network host="mail.YYYYY.com" port="25"/>
			</smtp>
		</mailSettings>
	</system.net>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.