Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Webpages Email in ASP

Webpages Email in ASP

Sure! Here’s how you can send emails using ASP.NET Web Pages (WebMatrix) with the built-in Email helper:


Sending Email in ASP.NET Web Pages


1. Basic Email Sending

Use the Email helper to send a simple email:

@{    Email.Send(        to: "recipient@example.com",        subject: "Test Email from Web Pages",        body: "Hello! This is a test email sent from ASP.NET Web Pages."    );}<p>Email sent!</p>

2. Specifying From Address and SMTP Settings

To customize the sender and SMTP, set up your web.config:

<system.net>  <mailSettings>    <smtp from="your-email@example.com">      <network host="smtp.example.com" port="587" userName="your-username" password="your-password" enableSsl="true" />    </smtp>  </mailSettings></system.net>
  • Replace with your SMTP server details.

  • from is the default sender address.


3. Sending HTML Email

Use the optional isBodyHtml parameter:

@{    Email.Send(        to: "recipient@example.com",        subject: "HTML Email",        body: "<h1>Hello</h1><p>This is an <strong>HTML</strong> email.</p>",        isBodyHtml: true    );}

4. Sending Email with CC and BCC

@{    Email.Send(        to: "recipient@example.com",        subject: "Email with CC and BCC",        body: "Check CC and BCC recipients.",        cc: "ccperson@example.com",        bcc: "bccperson@example.com"    );}

5. Handling Errors

Wrap your Email.Send call in try-catch to handle exceptions:

@{    try    {        Email.Send("recipient@example.com", "Subject", "Body");        <p>Email sent successfully!</p>;    }    catch(Exception ex)    {        <p>Error sending email: @ex.Message</p>;    }}

Summary

FeatureUsage Example
Send basicEmail.Send(to, subject, body);
HTML emailEmail.Send(..., isBodyHtml: true);
CC, BCCEmail.Send(..., cc: "...", bcc: "...");
SMTP settingsConfigure in web.config under <system.net>

If you want me to help you with email templates, attachments, or more advanced mailing scenarios, just ask!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql