Send Email Using C#

CK CK 3788 
Created at
Updated at  
1,381 0 0

In C#, MailMessage is a class within the `System.Net.Mail` namespace used to represent an email message. It allows you to set properties like the sender, recipient, subject, body, attachments, and other email-related attributes. You can then use a `SmtpClient` object to send the message via a specified SMTP server.

SmtpMail is a deprecated class in C# for sending emails using the Simple Mail Transfer Protocol (SMTP). It's been replaced by the `System.Net.Mail` namespace, which provides more robust and feature-rich classes like SmtpClient for sending emails, MailMessage for composing the email content, and `Attachment` for adding attachments. While `SmtpMail` is still available for legacy code, it's highly recommended to use the `System.Net.Mail` namespace for modern email sending needs. 

A code snippet,posted on the dotnet newsgroup,about how to send email using C#.

 

<%@Import <mailto:%@Import> namespace="System.Web.Util"%>

try{
	MailMessage MyMail = new MailMessage();
	MyMail.To = "who";
	MyMail.From = "you";
	MyMail.BodyFormat = MailFormat.Html;
	MyMail.Body = "sometext";
	SmtpMail.Send(MyMail);
}
catch(Exception){}


 

Tags C# Mailing MailMessage SMTP SmtpMail Facebook X
Comments 0
Similar posts
  1. How To Send An E-mail By Code
    1,124
  2. Send An Email Using A Bean
    1,020
  3. Sending email messages in .Net
    1,041
  4. How to send email by TIdSMTP VCL ?
    1,023
  5. Set up an SMTP server on CentOS 7
    730
  6. Bash script to install postfix and sasl for sending email
    1,200
  7. Why SPF and DKIM Are Essential for Linux Email Servers?
    49
  1. C# Lists
    1,162
  2. Simple Example of IF/THEN using C#
    1,270
  3. Fast and Good Keyboard/Mouse Test without the message handler
    984
  4. Simple CGI Programming in C
    550
  5. C++ CGI Example working on Apache
    490
  6. Simple C# CGI working on Apache
    486
  7. How to send binary data through C# CGI app?
    998
  8. Interacting With TinyPic From C#
    1,314
  9. Creating A Watched Folder With Assigned Events
    1,672
  10. Calling Your Main Thread From A Worker Thread In C#
    551
  11. HashTable Tutorial In C#
    1,794
  12. Stack Tutorial In C#
    673
  13. Queue Tutorial In C#
    1,753
  14. Create PDF Files On the Fly in C#
    1,008
  15. How to call Visual C/C++ implemented DLL functions in C# - Simple DLLImport
    1,173
  16. How To Read And Write A Cookie
    365
  17. Using C# With Cookies
    629
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    28
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    55
  3. How do I create animated background for Google Meet?
    22,830
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    271
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    103
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    168
  7. Array of arguments passed to script in PHP
    97
  8. Invalid Auction Storms in Ad Tech
    106
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    207
  10. The Two Clocks of Ad Server Architecture
    77
  11. Frequency Cap Architecture Overview
    526
  12. Collecting Proof-of-Play from 100,000 Screens
    152
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    302
  14. What is RedisVL?
    114
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    246
  16. TPU & GPU Cluster Management Tools
    257
  17. The Concept of Scaffolding in AI Agents
    244
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    596
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    267
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    353
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    206
  22. Machine Learning: Training vs. Ranking
    229
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    228
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    202
  25. Designing a Data Curation System Around a Vector Database
    230
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    671
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    200
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    232
  30. Understanding Data Lineage
    271