Gmail හරහා .NET හි විද්‍යුත් තැපෑල යැවීම


892

ඊ-තැපෑලක් යැවීම සඳහා මගේ සත්කාරක සමාගම මත විශ්වාසය තබනවා වෙනුවට, මගේ ජීමේල් ගිණුම භාවිතයෙන් විද්‍යුත් තැපැල් පණිවිඩ යැවීමට මම සිතුවෙමි . ඊමේල් යනු මගේ ප්‍රදර්ශනයේ මා වාදනය කරන සංගීත කණ්ඩායම් වලට පුද්ගලීකරණය කළ ඊමේල් ය.

එය කළ හැකිද?


1
< systemnetmail.com > බොහෝ විට විකාර සහගත තනි වෙබ් අඩවියක් සඳහා වෙන් කර ඇති වෙබ් අඩවිය විය හැකිය ... නමුත් .NET හරහා තැපැල් යැවීම ගැන ඔබට දැන ගැනීමට අවශ්‍ය සෑම දෙයක්ම එයට ඇත. එය ASP.NET හෝ ඩෙස්ක්ටොප් වේවා. < systemwebmail.com > යනු තනතුරේ මුල් URL ය, නමුත් .NET 2.0 සහ ඊට ඉහළින් භාවිතා නොකළ යුතුය.
ඇඩම් හේල්

13
ඔබ ASP.Net Mvc භාවිතා කරන්නේ නම් MvcMailer දෙස බැලීමට මම නිර්දේශ කරමි: github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide
noocyte

යවන්නාගේ සීමාවන් දැනුවත් විය (මම ඔබේ සංගීත කණ්ඩායම මේ ජීවිතය සාර්ථක ප්රමාණවත් බලාපොරොත්තු) කරුණාකර support.google.com/a/bin/answer.py?hl=en&answer=166852
Simon_Weaver

පහසුම ක්‍රමය එය කියවන්න. stackoverflow.com/questions/9201239/…
ජොයෙල් සැන්ටොස්

මට ඇති ගැටලුව නම් මගේ මුරපදයේ බ්ලැක් ස්ලෑෂ් "\\" තිබීමයි , එය පිටපත් කළ විට එය ගැටළු ඇති වන බව නොදැන පිටපත් කරමි.
සට්බීර් කිරා

Answers:


1074

System.Net.Mailඅතහැර දැමූ ඒවා නොව භාවිතා කිරීමට වග බලා ගන්න System.Web.Mail. එස්එස්එල් සමඟ System.Web.Mailකිරීම අනවසර දිගු වල බරපතල අවුලකි.

using System.Net;
using System.Net.Mail;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}

49
පසුගිය xx මිනිත්තු ගණන තුළ ඔබ ඕනෑවට වඩා යවා ඇති බව ගූගල් හදිසියේම තීරණය කළහොත් ඔබට තවමත් පරිශීලකයා දෝෂ වලට ලොග් නොවී සිටිය හැකිය. ඔබ සැමවිටම ට්‍රයිසෙන්ඩ් එකක් එක් කළ යුතුය, එය යම් වේලාවක් නින්දට යාමේ දෝෂයක් නම්, නැවත උත්සාහ කරන්න.
ජේසන්

73
සිත්ගන්නාසුලු සටහන: ඔබ 'UseDefaultCredentials = false' සහ 'Credentials = ...' මාරු කළහොත් එය සත්‍යාපනය නොවේ.
නේතන් වීල්

13
මෙම ක්‍රමය භාවිතා කරමින් එස්පීඑෆ් සමඟ කිසිදු ගැටළුවක් නොමැත. සෑම ඊමේල් සේවාදායකයෙකුටම මෙය හරියටම කිරීමට වින්‍යාසගත කළ හැකිය. ඔබ යවන්නා ලෙස ඔබේම සේවාදායකයක් (එනම් වෙනත් දෙයක් smtp.gmail.com) භාවිතා කරන්නේ නම් ඔබට ගැටළු ඇති විය හැකිය something@gmail.com. Btw: smtp.gmail.comයවන්නාගේ ලිපිනය ඔබගේ නොවේ නම් ස්වයංක්‍රීයව නැවත ලියයි .
මීනර්ස්බර්

24
විවිධ වෙනස් කිරීම් අත්හදා බැලීමෙන් පවා මට මෙම කාර්යය ලබා ගැනීමට අපහසු විය. අදාළ පෝස්ට් එකක යෝජනා කර ඇති පරිදි, ඊමේල් සාර්ථකව යැවීම වලක්වන්නේ ඇත්ත වශයෙන්ම මගේ ප්‍රති-වයිරස බව මට පෙනී ගියේය. ප්‍රශ්නයට භාජනය වන ප්‍රති-වයිරසය මැක්අෆී වන අතර එහි “ප්‍රවේශ ආරක්ෂණ” හි “ප්‍රති-වයිරස සම්මත ආරක්ෂණ” කාණ්ඩයක් ඇති අතර එයට “විද්‍යුත් තැපැල් යැවීමෙන් විශාල තැපැල් පණුවන් වළක්වන්න” රීතියක් ඇත. එම රීතිය වෙනස් කිරීම / අක්‍රීය කිරීම මෙම කේතය මා වෙනුවෙන් වැඩ කරයි!
yourbuddypal

18
මට 5.5.1 සත්‍යාපනය අවශ්‍ය වූ දෝෂ පණිවිඩයක් ලැබෙමින් තිබුනේ මා විසින් සාධක දෙකක් සත්‍යාපනය කර ඇති ගිණුමක් (මගේ පුද්ගලික එකක්) සමඟ පරීක්‍ෂා කරන බව වටහා ගන්නා තෙක්ය. වරක් මා සතුව නැති ගිණුමක් භාවිතා කළ විට එය හොඳින් ක්‍රියාත්මක විය. මගේ අයදුම්පත සඳහා මුරපදයක් ජනනය කළ හැකිව තිබුනේ මගේ පුද්ගලික අක්‍ෂරයෙන් මා පරීක්‍ෂා කරන නමුත් මට එය කිරීමට අවශ්‍ය නොවීය.
නික් ඩිවෝර්

157

ඉහත පිළිතුර ක්‍රියාත්මක නොවේ. ඔබ සැකසිය යුතුය, DeliveryMethod = SmtpDeliveryMethod.Networkනැතහොත් එය " සේවාදායකයා සත්‍යාපනය නොකළ " දෝෂයක් සමඟ නැවත පැමිණේ . එසේම කල් ඉකුත්වීම සැමවිටම හොඳ අදහසකි.

සංශෝධිත කේතය:

using System.Net.Mail;
using System.Net;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@yahoo.com", "To Name");
const string fromPassword = "password";
const string subject = "test";
const string body = "Hey now!!";

var smtp = new SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
    Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
    Subject = subject,
    Body = body
})
{
    smtp.Send(message);
}

3
සිත්ගන්නා සුළු; එය මගේ යන්ත්‍රයේ (ටීඑම්) ක්‍රියා කරයි. නමුත් මෙය පිළිගත හැකි යැයි පෙනෙන බැවින්, මම එය මගේ පිළිතුරට එකතු කරමි.
ඩොමිනික්

3
හ්ම් මගේ අනුමානය නම් SmtpDeliveryMethod.Network යනු පෙරනිමියයි, නමුත් සමහර විට IIS හි ධාවනය වන විට පෙරනිමිය වෙනස් වේ --- ඔබ කරමින් සිටියේ එයද?
ඩොමිනික්

3
මම කොන්සෝලය යෙදුමේ එකම කේතයක් භාවිතා කරමි, එය දෝෂයක් හරහා "තැපැල් යැවීම අසමත් විය."
කාර්තික්යන් පී

5
මෙම පිළිතුර ක්‍රියාත්මක නොවේ. කරුණාකර, stackoverflow.com/questions/34851484/…

115

"සේවාදායකයකින්" වැඩ කිරීමට අනෙක් පිළිතුරු සඳහා , ජීමේල් ගිණුමේ අඩු ආරක්‍ෂිත යෙදුම් සඳහා පළමුව ප්‍රවේශය සක්‍රිය කරන්න .

මෑතකදී ගූගල් එහි ආරක්ෂක ප්‍රතිපත්තිය වෙනස් කළ බව පෙනේ. මෙහි විස්තර කර ඇති පරිදි ඔබගේ ගිණුම් සැකසුම් වෙනස් කරන තුරු ඉහළම ශ්‍රේණිගත කළ පිළිතුර තවදුරටත් ක්‍රියාත්මක නොවේ: https://support.google.com/accounts/answer/6010255?hl=en-GBරූප විස්තරය මෙහි ඇතුළත් කරන්න

රූප විස්තරය මෙහි ඇතුළත් කරන්න

2016 මාර්තු වන විට ගූගල් නැවත සැකසුම් ස්ථානය වෙනස් කළේය!


4
මෙය මට වැඩ කළා. එසේම. මට එම ආරක්ෂාව අක්‍රිය කිරීමට අවශ්‍ය යැයි විශ්වාස නැත. නැවත සිතා බැලීමට අවශ්‍ය විය හැකිය ...
සුලි

4
ආරක්ෂක දෘෂ්ටි කෝණයෙන් පියවර 2 ක සත්‍යාපනය සක්‍රිය කර යෙදුම් මුරපදය ජනනය කර භාවිතා කිරීම වඩා හොඳය- නව ආරක්ෂක ප්‍රතිපත්ති අනුව .Net හි විද්‍යුත් තැපෑලක් යවන්නේ කෙසේද?
මයිකල් ෆ්‍රයිඩ්ජිම්

2
@BCS මෘදුකාංගය, inmy වැඩසටහන, පරිශීලකයා මගේ වැඩසටහන භාවිතා කළ යුතු ඕනෑම විද්‍යුත් තැපෑලක් ඇතුල් කරයි. 2-සාධක සත්‍යාපනය සක්‍රිය කර තිබුණත් විද්‍යුත් තැපෑල යැවීමට විද්‍යුත් තැපැල් පරිශීලකයාට හැකි වන්නේ කෙසේද?
ඇල '

ගූගල් හි GMail හරහා ඊමේල් යැවීමට / ලැබීමට ඔබට Microsoft Outlook ග්‍රාහකයක් (ඩෙස්ක්ටොප් එකක, ජංගම දුරකථනයක් වැනි) භාවිතා කිරීමට අවශ්‍ය නම් වෙනස් කළ යුතු එකම සැකසුම මෙයයි.
බ්‍රෙට් රිගි

42

මෙය ඇමුණුම් සහිතව විද්‍යුත් තැපෑලක් යැවීමයි .. සරල හා කෙටි ..

මූලාශ්‍රය: http://coding-issues.blogspot.in/2012/11/sending-email-with-attachments-from-c.html

using System.Net;
using System.Net.Mail;

public void email_send()
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("your mail@gmail.com");
    mail.To.Add("to_mail@gmail.com");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
    mail.Attachments.Add(attachment);

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("your mail@gmail.com", "your password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);

}

23

නවීන ආරක්ෂක ප්‍රමිතීන් භාවිතා නොකරන සමහර යෙදුම් හෝ උපාංග වලින් පුරනය වීමේ උත්සාහයන් Google විසින් අවහිර කරනු ඇත. මෙම යෙදුම් සහ උපාංග වලට ඇතුළුවීම පහසු බැවින්, ඒවා අවහිර කිරීම ඔබගේ ගිණුම ආරක්ෂිතව තබා ගැනීමට උපකාරී වේ.

නවතම ආරක්ෂක ප්‍රමිතීන්ට සහය නොදක්වන යෙදුම් සඳහා උදාහරණ කිහිපයක් ඇතුළත් වේ:

  • IOS 6 හෝ ඊට අඩු ඔබගේ iPhone හෝ iPad හි ඇති තැපැල් යෙදුම
  • 8.1 නිකුතුවට පෙර ඔබගේ වින්ඩෝස් දුරකථනයේ තැපැල් යෙදුම
  • මයික්‍රොසොෆ්ට් අවුට්ලුක් සහ මොසිල්ලා තණ්ඩර්බර්ඩ් වැනි සමහර ඩෙස්ක්ටොප් තැපැල් සේවාදායකයින්

එමනිසා, ඔබගේ ගූගල් ගිණුමේ අඩු ආරක්‍ෂිත පුරනය වීම සක්‍රීය කළ යුතුය.

ගූගල් ගිණුමට ඇතුල් වූ පසු, වෙත යන්න:

https://myaccount.google.com/lesssecureapps
හෝ
https://www.google.com/settings/security/lesssecureapps

C # හි, ඔබට පහත කේතය භාවිතා කළ හැකිය:

using (MailMessage mail = new MailMessage())
{
    mail.From = new MailAddress("email@gmail.com");
    mail.To.Add("somebody@domain.com");
    mail.Subject = "Hello World";
    mail.Body = "<h1>Hello</h1>";
    mail.IsBodyHtml = true;
    mail.Attachments.Add(new Attachment("C:\\file.zip"));

    using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
    {
        smtp.Credentials = new NetworkCredential("email@gmail.com", "password");
        smtp.EnableSsl = true;
        smtp.Send(mail);
    }
}

19

මට එය වැඩ කිරීමට නම්, මගේ ජීමේල් ගිණුම වෙනත් යෙදුම් වලට ප්‍රවේශය ලබා ගැනීමට හැකි විය. මේ සමග ඇති "ආරක්ෂාව අඩු යෙදුම් සක්රිය" සහ සිදු : මෙම ලින්ක් එක භාවිතා කර https://accounts.google.com/b/0/DisplayUnlockCaptcha


මෙම පිළිතුර ඉහළට යා යුතුය.
හුරුබුහුටි වලසා

17

මෙන්න මගේ අනුවාදය: " Gmail භාවිතා කරමින් C # විද්‍යුත් තැපෑල යවන්න ".

using System;
using System.Net;
using System.Net.Mail;

namespace SendMailViaGmail
{
   class Program
   {
   static void Main(string[] args)
   {

      //Specify senders gmail address
      string SendersAddress = "Sendersaddress@gmail.com";
      //Specify The Address You want to sent Email To(can be any valid email address)
      string ReceiversAddress = "ReceiversAddress@yahoo.com";
      //Specify The password of gmial account u are using to sent mail(pw of sender@gmail.com)
      const string SendersPassword = "Password";
      //Write the subject of ur mail
      const string subject = "Testing";
      //Write the contents of your mail
      const string body = "Hi This Is my Mail From Gmail";

      try
      {
        //we will use Smtp client which allows us to send email using SMTP Protocol
        //i have specified the properties of SmtpClient smtp within{}
        //gmails smtp server name is smtp.gmail.com and port number is 587
        SmtpClient smtp = new SmtpClient
        {
           Host = "smtp.gmail.com",
           Port = 587,
           EnableSsl = true,
           DeliveryMethod = SmtpDeliveryMethod.Network,
           Credentials    = new NetworkCredential(SendersAddress, SendersPassword),
           Timeout = 3000
        };

        //MailMessage represents a mail message
        //it is 4 parameters(From,TO,subject,body)

        MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
        /*WE use smtp sever we specified above to send the message(MailMessage message)*/

        smtp.Send(message);
        Console.WriteLine("Message Sent Successfully");
        Console.ReadKey();
     }

     catch (Exception ex)
     {
        Console.WriteLine(ex.Message);
        Console.ReadKey();
     }
    }
   }
 }

8
ඔබේ ලිපිය ඇත්ත වශයෙන්ම ප්‍රශ්නයට පිළිතුරු සැපයිය හැකි වුවත්, පිළිතුරේ අත්‍යවශ්‍ය කොටස් මෙහි ඇතුළත් කිරීම වඩාත් සුදුසු වන අතර, යොමු කිරීම සඳහා සබැඳිය සපයන්න. සිරස් පිටාර ගැලීම එහි ප්‍රශ්න සහ පිළිතුරු තරම්ම ප්‍රයෝජනවත් වන අතර, ඔබේ බ්ලොග් සත්කාරක සමාගම පහව ගියහොත් හෝ ඔබේ URL එහා මෙහා ගෙන ගියහොත්, මෙම පිළිතුර නිෂ් .ල වේ. ස්තූතියි!
සර්නෝල්ඩ්

15

මෙම කේතය හොඳින් ක්‍රියාත්මක වනු ඇතැයි මම බලාපොරොත්තු වෙමි. ඔබට උත්සාහ කළ හැකිය.

// Include this.                
using System.Net.Mail;

string fromAddress = "xyz@gmail.com";
string mailPassword = "*****";       // Mail id password from where mail will be sent.
string messageBody = "Write the body of the message here.";


// Create smtp connection.
SmtpClient client = new SmtpClient();
client.Port = 587;//outgoing port for the mail.
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(fromAddress, mailPassword);


// Fill the mail form.
var send_mail = new MailMessage();

send_mail.IsBodyHtml = true;
//address from where mail will be sent.
send_mail.From = new MailAddress("from@gmail.com");
//address to which mail will be sent.           
send_mail.To.Add(new MailAddress("to@example.com");
//subject of the mail.
send_mail.Subject = "put any subject here";

send_mail.Body = messageBody;
client.Send(send_mail);

2
message send_mail = නව MailMessage (); මෙම රේඛාව වැඩ කරන්නේ යැයි සිතන්නේ කෙසේද? ඔබට 'System.Net.Mail.MailMessage' යන්න 'System.Windows.Forms.Message' බවට ව්‍යංගයෙන් පරිවර්තනය කළ නොහැක
Debaprasad

10

මෙය ඇතුළත් කරන්න,

using System.Net.Mail;

ඊළගට,

MailMessage sendmsg = new MailMessage(SendersAddress, ReceiversAddress, subject, body); 
SmtpClient client = new SmtpClient("smtp.gmail.com");

client.Port = Convert.ToInt16("587");
client.Credentials = new System.Net.NetworkCredential("mail-id@gmail.com","password");
client.EnableSsl = true;

client.Send(sendmsg);

9

මූලාශ්‍රය : ASP.NET C # හි විද්‍යුත් තැපෑල යවන්න

පහත දැක්වෙන්නේ C # භාවිතා කරමින් තැපෑලක් යැවීම සඳහා වැඩ කරන කේතයකි, පහත උදාහරණයේ මම ගූගල් හි smtp සේවාදායකය භාවිතා කරමි.

කේතය ඉතා ස්වයං පැහැදිලි කිරීමකි, ඊමේල් සහ මුරපදය ඔබගේ විද්‍යුත් තැපැල් හා මුරපද අගයන් සමඟ ප්‍රතිස්ථාපනය කරන්න.

public void SendEmail(string address, string subject, string message)
{
    string email = "yrshaikh.mail@gmail.com";
    string password = "put-your-GMAIL-password-here";

    var loginInfo = new NetworkCredential(email, password);
    var msg = new MailMessage();
    var smtpClient = new SmtpClient("smtp.gmail.com", 587);

    msg.From = new MailAddress(email);
    msg.To.Add(new MailAddress(address));
    msg.Subject = subject;
    msg.Body = message;
    msg.IsBodyHtml = true;

    smtpClient.EnableSsl = true;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.Credentials = loginInfo;
    smtpClient.Send(msg);
}

Var වෙනුවට, මම NetworkCredential, MailMessage සහ SmtpClient වැනි පන්ති නාමයන් භාවිතා කර ඇත. එය මට වැඩ කරයි.
ජුයි ටෙස්ට්

8

ඔබට පසුබිම් විද්‍යුත් තැපෑලක් යැවීමට අවශ්‍ය නම් කරුණාකර පහත දේ කරන්න

 public void SendEmail(string address, string subject, string message)
 {
 Thread threadSendMails;
 threadSendMails = new Thread(delegate()
    {

      //Place your Code here 

     });
  threadSendMails.IsBackground = true;
  threadSendMails.Start();
}

සහ නාම අවකාශය එක් කරන්න

using System.Threading;

6

මේක උත්සාහ කරන්න,

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("your_email_address@gmail.com");
            mail.To.Add("to_address");
            mail.Subject = "Test Mail";
            mail.Body = "This is for testing SMTP mail from GMAIL";

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);
            MessageBox.Show("mail Send");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

5

මේ ආකාරයෙන් භාවිතා කරන්න

MailMessage sendmsg = new MailMessage(SendersAddress, ReceiversAddress, subject, body); 
SmtpClient client = new SmtpClient("smtp.gmail.com");

client.Port = Convert.ToInt32("587");
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("mail-id@gmail.com","MyPassWord");
client.Send(sendmsg);

මෙය අමතක නොකරන්න:

using System.Net;
using System.Net.Mail;

5

ජීමේල් හි ආරක්ෂක ගැටළු මඟහරවා ගැනීම සඳහා, ඔබ මුලින්ම ඔබගේ ජීමේල් සැකසුම් වලින් යෙදුම් මුරපදයක් ජනනය කළ යුතු අතර, ඔබ පියවර දෙකක සත්‍යාපනය භාවිතා කළත් විද්‍යුත් තැපෑලක් යැවීමට සැබෑ මුරපදයක් වෙනුවට මෙම මුරපදය භාවිතා කළ හැකිය.


4

Gmail / Outlook.com විද්‍යුත් තැපෑලෙන් යවන්නා වෙනස් කිරීම:

වංචා කිරීම වැළැක්වීම සඳහා - අත්තනෝමතික පරිශීලක ගිණුම් නාමයකින් යැවීමට Gmail / Outlook.com ඔබට ඉඩ නොදේ.

ඔබට යවන්නා සීමිත සංඛ්‍යාවක් සිටී නම් ඔබට මෙම උපදෙස් අනුගමනය කර Fromක්ෂේත්‍රය මෙම ලිපිනයට සැකසිය හැකිය : වෙනත් ලිපිනයකින් තැපැල් යැවීම

ඔබට අත්තනෝමතික ඊමේල් ලිපිනයකින් යැවීමට අවශ්‍ය නම් (වෙබ් අඩවියේ ප්‍රතිපෝෂණ පෝරමය වැනි පරිශීලකයා ඔවුන්ගේ විද්‍යුත් තැපැල් ලිපිනයට ඇතුළු වන අතර ඔවුන් ඔබට කෙලින්ම විද්‍යුත් තැපැල් කිරීමට අවශ්‍ය නැත) ඔබට කළ හැකි හොඳම දේ මෙයයි:

        msg.ReplyToList.Add(new System.Net.Mail.MailAddress(email, friendlyName));

ප්‍රතිපෝෂණ පිටුවක ඔබේ සංගීත කණ්ඩායමේ රසිකයාට පිළිතුරු සැපයීම සඳහා මෙය ඔබගේ විද්‍යුත් තැපැල් ගිණුමේ 'පිළිතුරු' එබීමට ඉඩ සලසයි, නමුත් ඔවුනට ඔබේ සත්‍ය විද්‍යුත් තැපෑල නොලැබෙනු ඇති අතර එය ටොන් ගණනක් අයාචිත තැපැල් වලට තුඩු දෙනු ඇත.

ඔබ පාලිත පරිසරයක සිටී නම් මෙය ඉතා හොඳය, නමුත් කරුණාකර සටහන් කරන්න සමහර ඊමේල් සේවාදායකයින් පිළිතුරු-ලිපිනය සඳහන් කර තිබියදීත් ලිපිනයෙන් ලිපිනය වෙත යවන බව මම දැක ඇත්තෙමි (මම දන්නේ නැහැ).


4

මට එකම ගැටළුවක් තිබුනි, නමුත් එය විසඳනු ලැබුවේ ජීමේල් හි ආරක්ෂක සැකසුම් වෙත ගොස් අඩු ආරක්‍ෂිත යෙදුම් වලට ඉඩ දීමෙනි . ඩොමිනික් සහ ඩොනී වෙතින් කේතය ක්‍රියාත්මක වේ, නමුත් ඔබ එම සැකසුම සක්‍රීය කළහොත් පමණි

ඔබ (ගූගල් වෙත) පුරනය වී ඇත්නම් ඔබට මෙම සබැඳිය අනුගමනය කර " අඩු ආරක්‍ෂිත යෙදුම් සඳහා ප්‍රවේශය " සඳහා " සක්‍රිය කරන්න" ටොගල කළ හැකිය.


4
using System;
using System.Net;
using System.Net.Mail;

namespace SendMailViaGmail
{
   class Program
   {
   static void Main(string[] args)
   {

      //Specify senders gmail address
      string SendersAddress = "Sendersaddress@gmail.com";
      //Specify The Address You want to sent Email To(can be any valid email address)
      string ReceiversAddress = "ReceiversAddress@yahoo.com";
      //Specify The password of gmial account u are using to sent mail(pw of sender@gmail.com)
      const string SendersPassword = "Password";
      //Write the subject of ur mail
      const string subject = "Testing";
      //Write the contents of your mail
      const string body = "Hi This Is my Mail From Gmail";

      try
      {
        //we will use Smtp client which allows us to send email using SMTP Protocol
        //i have specified the properties of SmtpClient smtp within{}
        //gmails smtp server name is smtp.gmail.com and port number is 587
        SmtpClient smtp = new SmtpClient
        {
           Host = "smtp.gmail.com",
           Port = 587,
           EnableSsl = true,
           DeliveryMethod = SmtpDeliveryMethod.Network,
           Credentials = new NetworkCredential(SendersAddress, SendersPassword),
           Timeout = 3000
        };

        //MailMessage represents a mail message
        //it is 4 parameters(From,TO,subject,body)

        MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
        /*WE use smtp sever we specified above to send the message(MailMessage message)*/

        smtp.Send(message);
        Console.WriteLine("Message Sent Successfully");
        Console.ReadKey();
     }
     catch (Exception ex)
     {
        Console.WriteLine(ex.Message);
        Console.ReadKey();
     }
}
}
}

2

Web.config වෙතින් තැපැල් යැවීම සහ අක්තපත්‍ර ලබා ගැනීම සඳහා එක් ක්‍රමයක් මෙන්න:

public static string SendEmail(string To, string Subject, string Msg, bool bodyHtml = false, bool test = false, Stream AttachmentStream = null, string AttachmentType = null, string AttachmentFileName = null)
{
    try
    {
        System.Net.Mail.MailMessage newMsg = new System.Net.Mail.MailMessage(System.Configuration.ConfigurationManager.AppSettings["mailCfg"], To, Subject, Msg);
        newMsg.BodyEncoding = System.Text.Encoding.UTF8;
        newMsg.HeadersEncoding = System.Text.Encoding.UTF8;
        newMsg.SubjectEncoding = System.Text.Encoding.UTF8;

        System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
        if (AttachmentStream != null && AttachmentType != null && AttachmentFileName != null)
        {
            System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(AttachmentStream, AttachmentFileName);
            System.Net.Mime.ContentDisposition disposition = attachment.ContentDisposition;
            disposition.FileName = AttachmentFileName;
            disposition.DispositionType = System.Net.Mime.DispositionTypeNames.Attachment;

            newMsg.Attachments.Add(attachment);
        }
        if (test)
        {
            smtpClient.PickupDirectoryLocation = "C:\\TestEmail";
            smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
        }
        else
        {
            //smtpClient.EnableSsl = true;
        }

        newMsg.IsBodyHtml = bodyHtml;
        smtpClient.Send(newMsg);
        return SENT_OK;
    }
    catch (Exception ex)
    {

        return "Error: " + ex.Message
             + "<br/><br/>Inner Exception: "
             + ex.InnerException;
    }

}

සහ web.config හි අනුරූප කොටස:

<appSettings>
    <add key="mailCfg" value="yourmail@example.com"/>
</appSettings>
<system.net>
  <mailSettings>
    <smtp deliveryMethod="Network" from="yourmail@example.com">
      <network defaultCredentials="false" host="mail.exapmple.com" userName="yourmail@example.com" password="your_password" port="25"/>
    </smtp>
  </mailSettings>
</system.net>

2

මෙය උත්සාහ කරන්න

public static bool Send(string receiverEmail, string ReceiverName, string subject, string body)
{
        MailMessage mailMessage = new MailMessage();
        MailAddress mailAddress = new MailAddress("abc@gmail.com", "Sender Name"); // abc@gmail.com = input Sender Email Address 
        mailMessage.From = mailAddress;
        mailAddress = new MailAddress(receiverEmail, ReceiverName);
        mailMessage.To.Add(mailAddress);
        mailMessage.Subject = subject;
        mailMessage.Body = body;
        mailMessage.IsBodyHtml = true;

        SmtpClient mailSender = new SmtpClient("smtp.gmail.com", 587)
        {
            EnableSsl = true,
            UseDefaultCredentials = false,
            DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
            Credentials = new NetworkCredential("abc@gmail.com", "pass")   // abc@gmail.com = input sender email address  
                                                                           //pass = sender email password
        };

        try
        {
            mailSender.Send(mailMessage);
            return true;
        }
        catch (SmtpFailedRecipientException ex)
        { 
          // Write the exception to a Log file.
        }
        catch (SmtpException ex)
        { 
           // Write the exception to a Log file.
        }
        finally
        {
            mailSender = null;
            mailMessage.Dispose();
        }
        return false;
}

1

වෙනත් පිළිතුරකින් පිටපත් කිරීම , ඉහත ක්‍රම ක්‍රියාත්මක වන නමුත් ජීමේල් සෑම විටම “සිට” සහ “පිළිතුරු” විද්‍යුත් තැපෑල සත්‍ය යැවීමේ ජීමේල් ගිණුම සමඟ ප්‍රතිස්ථාපනය කරයි. පෙනෙන විදිහට කෙසේ වෙතත් වැඩක් තිබේ:

http://karmic-development.blogspot.in/2013/10/send-email-from-aspnet-using-gmail-as.html

"3. ගිණුම් පටිත්තෙහි," ඔබ සතුව ඇති තවත් විද්‍යුත් තැපැල් ලිපිනයක් එක් කරන්න "යන සබැඳිය ක්ලික් කරන්න.

නැතහොත් විය හැකිය මෙය

යාවත්කාලීන 3: පා er ක ඩෙරෙක් බෙනට් පවසන්නේ, “විසඳුම වන්නේ ඔබේ ජීමේල් සැකසුම්: ගිණුම් සහ ඔබේ ජීමේල් ගිණුම හැර වෙනත් ගිණුමක්“ පෙරනිමිය ”කිරීමයි. මෙය පෙරනිමි ගිණුමේ විද්‍යුත් තැපෑලෙන් ජීමේල් වෙතින් ක්ෂේත්‍රය නැවත ලිවීමට හේතු වේ. ලිපිනය.


1

ඔබට උත්සාහ කළ හැකිය Mailkit. එය ඔබට තැපැල් යැවීම සඳහා වඩා හොඳ සහ අත්තිකාරම් ක්‍රියාකාරිත්වයක් ලබා දෙයි. ඔබ තව තවත් සොයා ගත හැකි මෙම උදාහරණයක් බලමු

    MimeMessage message = new MimeMessage();
    message.From.Add(new MailboxAddress("FromName", "YOU_FROM_ADDRESS@gmail.com"));
    message.To.Add(new MailboxAddress("ToName", "YOU_TO_ADDRESS@gmail.com"));
    message.Subject = "MyEmailSubject";

    message.Body = new TextPart("plain")
    {
        Text = @"MyEmailBodyOnlyTextPart"
    };

    using (var client = new SmtpClient())
    {
        client.Connect("SERVER", 25); // 25 is port you can change accordingly

        // Note: since we don't have an OAuth2 token, disable
        // the XOAUTH2 authentication mechanism.
        client.AuthenticationMechanisms.Remove("XOAUTH2");

        // Note: only needed if the SMTP server requires authentication
        client.Authenticate("YOUR_USER_NAME", "YOUR_PASSWORD");

        client.Send(message);
        client.Disconnect(true);
    }

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.