Skip to content

Instantly share code, notes, and snippets.

@AnanoAspanidze
Last active November 10, 2017 11:47
Show Gist options
  • Save AnanoAspanidze/5d8d87477b53dc7b26ac1351198615f6 to your computer and use it in GitHub Desktop.
Save AnanoAspanidze/5d8d87477b53dc7b26ac1351198615f6 to your computer and use it in GitHub Desktop.
//returns string
PopulateBody();
//returns bool
SendEmai("email","subject", "body", true);
<div class="email-background" style="background-image:none;background-repeat:repeat;background-position:top left;background-attachment:scroll;padding-top:10px;padding-bottom:10px;padding-right:10px;padding-left:10px;">
<div class="email-container" style="max-width:500px;background-color:#fff;background-image:none;background-repeat:repeat;background-position:top left;background-attachment:scroll;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;overflow:hidden;border-radius:5px;">
<p style="margin-top:20px;margin-bottom:5px;margin-right:20px;margin-left:20px;font-size:16px;color:#666;line-height:1.2;font-weight:300;">
konnichiwa ^^
</p>
<p style="margin-top:5px;margin-bottom:20px;margin-right:20px;margin-left:20px;font-size:16px;color:#666;line-height:1.2;font-weight:300;">
ამ მეილმა გააუქმა გამოწერა: {Email}
</p>
</div>
</div>
https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not
private string PopulateBody()
{
string body = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/mail/htmlMail.html")))
{
body = reader.ReadToEnd();
}
//body = body.Replace("{variableName}", variableValue);
return body;
}
public bool SendEmail(string userMail, string subject, string body, bool isHtml)
{
try
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From = new System.Net.Mail.MailAddress("registration@geolab.edu.ge");
mail.To.Add(userMail);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = isHtml;
System.Net.Mail.SmtpClient SmptServer = new System.Net.Mail.SmtpClient("in-v3.mailjet.com");
SmptServer.Port = 587;
SmptServer.Credentials = new System.Net.NetworkCredential("497c9a7a91307238c7eb41e4fce8d53c", "8cfc2ef7bdb10ce4a0ac5ee629d11ae5");
SmptServer.EnableSsl = true;
SmptServer.Send(mail);
//System.Net.Mail.SmtpClient SmptServer = new System.Net.Mail.SmtpClient("smtp.gmail.com");
//SmptServer.Port = 587;
//SmptServer.Credentials = new System.Net.NetworkCredential("registration@geolab.edu.ge", "anano2016");
return true;
}
catch
{
return false;
}
}
//gmail smtp service-ის მეშვეობით მეილის გაგზავნის პირველი მცდელობის შემდეგ თქვენს ელ.ფოსტაზე
//(რომლითაც აგზავნით მეილს) მოგივათ მეილი, რომელიც მოგთხოვთ, დაბლა დაწიოთ უსაფრთხოება,
//რომ კოდით შეძლოთ მეილის გაგზავნა. დაადასტურეთ და შემდეგ ისევ შეძლებთ ყველაფრის უკან დაბრუნებას.
//თუ ამის შემდეგ მეილი მაინც ვერ გააგზავნეთ, დალოგინდით, ამ ლინკზე შედით, Allow less secure apps:
//ON მონიშნეთ და ახლიდან სცადეთ.
//https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment