सी # में ईमेल कैसे भेजें

इस चरण-दर-चरण मार्गदर्शिका में, हम .NET के लिए Aspose.Email का उपयोग करके C# में ईमेल भेजने का तरीका साझा करते हैं। हम इस सी# कंसोल एप्लिकेशन में जीमेल एसएमटीपी सर्वर का उपयोग करके ईमेल भेज रहे हैं, लेकिन आप किसी भी प्रकार के .NET अनुप्रयोगों में किसी भी एसएमटीपी सर्वर का उपयोग करके ईमेल भेज सकते हैं।

सी#में ईमेल भेजने के चरण

  1. सेटअप Aspose.Email for .NET NuGet पैकेज मैनेजर से
  2. निम्नलिखित नाम स्थान शामिल करें: Aspose.Email, Aspose.Email.Clients, और Aspose.Email.Clients.Smtp
  3. Aspose.Email.License वर्ग का उपयोग करके लाइसेंस लागू करें
  4. MailMessage कक्षा . का उपयोग करके एक नया ईमेल संदेश बनाएं
  5. SmtpClient कक्षा का उदाहरण बनाएं
  6. के माध्यम से ईमेल भेजने के लिए जीमेल एसएमटीपी क्लाइंट जानकारी सेट करें
  7. SmtpClient वर्ग की भेजें विधि का उपयोग करके email भेजें

सी # का उपयोग कर ईमेल भेजने के लिए कोड

using System;
//Add Aspose.Email for .NET package reference
//Use following namespaces to convert OTG to PDF format
using Aspose.Email;
using Aspose.Email.Clients;
using Aspose.Email.Clients.Smtp;
namespace SendEmailUsingSMTPServer
{
class Program
{
static void Main(string[] args)
{
//Set Aspose license before sending email through Gmail SMTP
//using Aspose.Email for .NET
Aspose.Email.License AsposeEmailLicense = new Aspose.Email.License();
AsposeEmailLicense.SetLicense(@"c:\asposelicense\license.lic");
//create an instance of MailMessage
MailMessage EmailMessage = new MailMessage();
//Set email message properties which you want to specify
EmailMessage.Subject = "How to Send Mail Using SMTP Server in C#";
EmailMessage.To = "ReceiverEmail@EmailServer.com";
EmailMessage.Body = "This is a test of sending email using SMTP in C#.";
//Initiate an instance of SmptpClient class
SmtpClient SMTPEmailClient = new SmtpClient();
//Set SMTP client properties so the email message can get through the server
SMTPEmailClient.Host = "smtp.gmail.com";
SMTPEmailClient.Username = "YourEmail@gmail.com";
SMTPEmailClient.Password = "Your Gamil Password";
SMTPEmailClient.Port = 587;
SMTPEmailClient.SecurityOptions = SecurityOptions.SSLExplicit;
//Finally send the email message using Gmail's SMTP client
SMTPEmailClient.Send(EmailMessage);
}
}
}

समस्या जब आप सी # में जीमेल एसएमटीपी का उपयोग कर ईमेल भेजते हैं

आपको अपवाद का सामना करना पड़ सकता है जैसे “एसएमटीपी सर्वर को एक सुरक्षित कनेक्शन की आवश्यकता है या क्लाइंट प्रमाणित नहीं था।"। ऐसा इसलिए है क्योंकि जीमेल आपके एप्लिकेशन को कम सुरक्षित मानता है इसलिए हो सकता है कि वह अपने एसएमटीपी सेवर का उपयोग करके ईमेल भेजने की अनुमति न दे। Gmail SMTP समस्या को ठीक करने के लिए allow access to less secure apps to send email.

 हिन्दी