Skip to content

Instantly share code, notes, and snippets.

@Mark-Uri
Created May 8, 2025 20:01
Show Gist options
  • Save Mark-Uri/905aef3113e57860edfdea8495bd6372 to your computer and use it in GitHub Desktop.
Save Mark-Uri/905aef3113e57860edfdea8495bd6372 to your computer and use it in GitHub Desktop.
Film
using System.Net.Http;
using System.Text.Json;
using System.Net.Mail;
using System.Net;
class Program
{
static async Task Main()
{
try
{
Console.Write("Напишите названые фильма : ");
var title = Console.ReadLine();
var apiKey = "62a5b808";
var url = $"http://www.omdbapi.com/?apikey={apiKey}&t={title}";
using var client = new HttpClient();
var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
Console.WriteLine($"Ошибка запроса: {response.StatusCode}");
return;
}
using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
var root = doc.RootElement;
if (!root.TryGetProperty("Title", out var titleProp))
{
Console.WriteLine("Фильм не найден");
return;
}
// --------------------
var senderEmail = "[email protected]";
var senderPassword = "**** **** **** ****"; // Проблема с получением пароля, писал код как вы. Думаю должен работать
var receiverEmail = "[email protected]";
var mail = new MailMessage();
mail.From = new MailAddress(senderEmail);
mail.To.Add(receiverEmail);
mail.Subject = $"Информация о фильме: {titleProp}";
mail.IsBodyHtml = true;
mail.Body = $@"
<html>
<body style='font-family:Arial,sans-serif; background:#f9f9f9; padding:20px;'>
<div style='background:#fff; border-radius:10px; padding:20px; max-width:600px; margin:auto;'>
<h2 style='color:#1a73e8;'>Информация о фильме: {titleProp}</h2>
<p><strong>Год:</strong> {root.GetProperty("Year")}</p>
<p><strong>Жанр:</strong> {root.GetProperty("Genre")}</p>
<p><strong>Режиссер:</strong> {root.GetProperty("Director")}</p>
<p><strong>Актеры:</strong> {root.GetProperty("Actors")}</p>
<p><strong>Сюжет:</strong> {root.GetProperty("Plot")}</p>
<img src='{root.GetProperty("Poster")}' alt='Постер' style='max-width:100%; border:1px solid #ccc; border-radius:10px;' />
<p style='margin-top:20px; font-size:12px; color:#888;'>Отправлено {DateTime.Now:dd.MM.yyyy HH:mm}</p>
</div>
</body>
</html>";
var smtpClient = new SmtpClient("smtp.gmail.com")
{
Port = 587,
Credentials = new NetworkCredential(senderEmail, senderPassword),
EnableSsl = true
};
smtpClient.Send(mail);
Console.WriteLine("Письмо успешно отправлено!");
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка: {ex.Message}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment