• 0

[ASP.NET/C#] sending mail and confirmation


Question

I have a contact form for people to send me email.

1. I tried it using my email but didn't receive anything.

2. I want a confirmation message to appear for the user when they send an email, how do i do that?

I created the contact form using textbox control and not the Wizard in VS 2008.

Here's the code i have in contact page.

protected void PageLoad(object sender, EventArgs e)
	{
		if (IsPostBack)
		{
			SmtpClient sc = new SmtpClient("smtp.DOMAIN.com");
			StringBuilder sb = new StringBuilder();
			MailMessage msg = null;

			sb.Append("Email from: " + txtEmail.Text + "\n");
			sb.Append("Message: " + txtMessage.Text + "\n");

			try
			{
				msg = new MailMessage(txtEmail.Text,
					"email here, i know", "Message from website",
					sb.ToString());

				sc.Send(msg);
			}
			catch (Exception ex)
			{
				//something bad happend
				Response.Write("Somethinghappend!");
			}
			finally
			{
				if (msg != null)
				{
					msg.Dispose();
				}
			}
		}
	}

and added this to web.config

<system.net>;
		<mailSettings>
			<smtp>
				<network host="smtp.DOMAIN.com"
						 password="password"
						 userName="username"/>
			</smtp>
		</mailSettings>
	</system.net>;

1 answer to this question

Recommended Posts

  • 0

something like this:

try

{

msg = new MailMessage(txtEmail.Text,

"email here, i know", "Message from website",

sb.ToString());

sc.Send(msg);

Response.Write("Something happend!");

}

catch (Exception ex)

{

//something bad happend

Response.Write("Somethinghappend!");

}

finally

{

if (msg != null)

{

Response.Write("Nothingend!");

msg.Dispose();

}

}

If you step through the code, odds are you'll get a stop on sc.Send(msg) telling you the smtp server connection failed, which is why you never got an email.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • just in time for it to be replaced with something that makes everyone unhappy! - The Microsoft way
    • Is this written by AI? The article contradicts itself and doesn't even line up with the title.
    • Pale Moon 33.7.2 by Razvan Serea Pale Moon is an Open Source, Goanna-based web browser available for Microsoft Windows, Linux and Android, focusing on efficiency and ease of use. Make sure to get the most out of your browser! Pale Moon offers you a browsing experience in a browser completely built from its own, independently developed source that has been forked off from Firefox/Mozilla code, with carefully selected features and optimizations to improve the browsers speed, resource use, stability and user experience, while offering full customization and a growing collection of extensions and themes to make the browser truly your own. Features: Optimized for modern processors Based on proprietary optimized layout engine (Goanna) Safe: forked from mature Mozilla code and regularly updated Secure: Additional security features and security-aware development Supported by our user community, and fully non-profit Familiar, efficient, fully customizable interface Support for full themes: total freedom over any elements design Support for easily-created lightweight themes (skins) Smooth and speedy page drawing and script processing Increased stability: experience fewer browser crashes Support for many Firefox extensions Support for a growing number of Pale Moon exclusive extensions Extensive and growing support for HTML5 and CSS3 Many customization and configuration options Pale Moon 33.7.2 release notes: Addressed PWN2OWN-2025-1 (out of bounds read or write in promise) DiD Addressed PWN2OWN-2025-2 (out of bounds read or write when using the ExtractLinearSum optimization) DiD Fixed potential unexpected behavior in embedded protobuf code. DiD Fixed an issue with potentially uninitialized contrast values when enhanced device contrast values can not be read from the O.S. DiD Fixed potential sanitization issues with devtools' "Copy as curl" feature. It should be noted that we do not currently offer cross-platform "curl" features, so this is another DiD for this release. Download: Pale Moon (64-bit) | Portable 64-bit | ~40.0 MB (Freeware) Download: Pale Moon (32-bit) | Portable 32-bit Links: Pale Moon Homepage | Add-ons | Themes | Extensions | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Another disappointing rumor: iPhone 17 won't get a ProMotion display by Hamid Ganji With the iPad Pro in 2017, Apple introduced a new type of display technology for its devices, dubbed ProMotion. The ProMotion feature enables a variable refresh rate, ranging from 24Hz to 120Hz, and it has a critical role in enhancing display sharpness and responsiveness. With the iPhone 13 Pro and iPhone 13 Pro Max in 2021, the ProMotion feature landed on iPhones, but it has stuck with the Pro variants since then, leaving the standard and Plus versions with a regular Super Retina display. While customers expected to get a ProMotion display on the vanilla iPhone 17, and even some rumors hinted at this possibility, the latest leaks suggest ProMotion remains with the Pro iPhone variants for another generation. According to Chinese leaker Fixed Focus Digital on Weibo, Apple has decided to keep the ProMotion feature exclusive to iPhone 17 Pro and Pro Max, and the rest of the lineup would launch with a “normal 120hz screen”. This Chinese leaker has conflicting reports about Apple’s future products. For now, we should take this claim with a pinch of salt and wait for more confirmation from the Apple supply chain insiders. In September last year, analyst Ross Young said the entire 17 lineup would get the ProMotion feature and the Always-on display (via 9to5mac). Young is also a credible source for Apple-related news, but too many conflicting rumors around upcoming iPhones make us question every claim. The only thing that seems certain so far is that Apple will increase the screen refresh rate on the iPhone 17 and 17 Air to 120Hz, which is a significant increase from the current 60Hz on the iPhone 16 base and Plus variants. Also, by boosting the iPhone 17 and 17 Air refresh rate to 120Hz, Apple is more likely to retain the ProMotion feature for the Pro models in the lineup to differentiate devices better from a marketing standpoint.
    • The article clearly states multiple times that he will DONATE his wealth. There's no mention of any loan, but haters gonna hate. He doesn't need to do this, you know? He could just give all that money to his kids and call it a day.
  • Recent Achievements

    • Week One Done
      Jim Dugan earned a badge
      Week One Done
    • Week One Done
      Adam Todd earned a badge
      Week One Done
    • Contributor
      Ed B went up a rank
      Contributor
    • One Month Later
      moporcho earned a badge
      One Month Later
    • One Month Later
      Parotel earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      211
    2. 2
      snowy owl
      156
    3. 3
      ATLien_0
      134
    4. 4
      Xenon
      119
    5. 5
      +FloatingFatMan
      113
  • Tell a friend

    Love Neowin? Tell a friend!