C# - Send Email with Attachment

  • 0 Replies
  • 156 Views

0 Members and 1 Guest are viewing this topic.

Offline Omega

    *
  • The Boss (Admin)
  • Black Hat Sec Member
  • Telegram: @BLACKHATSEC_FORUM
  • Posts: 190
  • Popularity: +1/-0
  • God of Malware
    • View Profile
    • Awards
« on: March 14, 2022, 09:20:57 AM »
C# - Send Email with Attachment
'Sends an email with a option for an attachment
Code
static void SendEmail(string fromEmail, string toEmail, string subject, string body, string gmailUser, string gmailPass, string attachPath)
        {
            try
            {
                //Coded by Rue
                MailMessage message = new MailMessage(fromEmail, toEmail, subject, body);
                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

                smtp.EnableSsl = true;
                smtp.Credentials = new NetworkCredential(gmailUser, gmailPass);

                if (attachPath != string.Empty | attachPath != null)
                {
                    Attachment attach = new Attachment(attachPath);
                    message.Attachments.Add(attach);
                }

                smtp.Send(message);
            }
            catch
            {  }
        }
  • Discord: BLACK HAT SEC#5222
  • [+]
  • [-]

  •