Skip to content

Commit

Permalink
Debugging password
Browse files Browse the repository at this point in the history
  • Loading branch information
RikuVirtanen committed Nov 29, 2023
1 parent 9845284 commit da95ecd
Show file tree
Hide file tree
Showing 15 changed files with 452 additions and 390 deletions.
8 changes: 8 additions & 0 deletions Frends.SMTP.SendEmail/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Changelog

## [1.1.0] - 2023-11-29
### Fixed
- Fixed issue with the attachments can't be given as expression

## [1.0.3] - 2023-11-03
### Added
- Fix missing XML comments.

## [1.0.2] - 2023-11-03
### Added
- Fix bug #20 - Missing Frends tasks metadata file

## [1.0.1] - 2023-05-15
### Fixed
- Fix bug #14 - NullReferenceException when field with 'Expression' type is empty

## [1.0.0] - 2022-02-09
Expand Down
41 changes: 19 additions & 22 deletions Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using NUnit.Framework;
using System;
using System.IO;
using Frends.SMTP.SendEmail.Definitions;

namespace Frends.SMTP.SendEmail.Tests
{
/// <summary>
/// NOTE: To run these unit tests, you need an SMTP test server. Fill in the properties below with your values.
/// </summary>
[TestFixture]
public class SendEmailTests
{
// ****************************************** FILL THESE ******************************************************
private const string USERNAME = "apikey";
private const string PASSWORD = "";
private const string SMTPADDRESS = "smtp.sendgrid.net";
private const string TOEMAILADDRESS = "jefim.borissov@hiq.fi";
private const string FROMEMAILADDRESS = "jefim.borissov@hiq.fi";
private static readonly string USERNAME = "apikey"; // Environment.GetEnvironmentVariable("Frends_SMTP_Username");

Check warning on line 12 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.

Check warning on line 12 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.
private static readonly string PASSWORD = Environment.GetEnvironmentVariable("SMTP_PASSWORD"); // Environment.GetEnvironmentVariable("Frends_SMTP_Password");

Check warning on line 13 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.

Check warning on line 13 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.
private static readonly string SMTPADDRESS = "smtp.sendgrid.net"; // Environment.GetEnvironmentVariable("Frends_SMTP_Address");

Check warning on line 14 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.

Check warning on line 14 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.
private static readonly string TOEMAILADDRESS = "jefim.borissov@hiq.fi"; // Environment.GetEnvironmentVariable("Frends_SMTP_Email");

Check warning on line 15 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.

Check warning on line 15 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.
private static readonly string FROMEMAILADDRESS = "jefim.borissov@hiq.fi"; // Environment.GetEnvironmentVariable("Frends_SMTP_Email");

Check warning on line 16 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.

Check warning on line 16 in Frends.SMTP.SendEmail/Frends.Smtp.SendEmail.Tests/SendEmailTests.cs

View workflow job for this annotation

GitHub Actions / build / Build on windows-latest

Remove this commented out code.
private const int PORT = 587;
private const bool USESSL = true;
private const bool USEWINDOWSAUTHENTICATION = false;
Expand Down Expand Up @@ -71,12 +69,10 @@ public void EmailTestSetup()
MessageEncoding = "utf-8"
};

var passwordFromEnvironment = Environment.GetEnvironmentVariable("SMTP_PASSWORD");

_options = new Options()
{
UserName = USERNAME,
Password = string.IsNullOrWhiteSpace(passwordFromEnvironment) ? PASSWORD : passwordFromEnvironment,
Password = PASSWORD,
SMTPServer = SMTPADDRESS,
Port = PORT,
UseSsl = USESSL,
Expand All @@ -97,7 +93,7 @@ public void SendEmailWithPlainText()
var input = _input;
input.Subject = "Email test - PlainText";

var result = SMTP.SendEmail(input, null, _options, new System.Threading.CancellationToken());
var result = SMTP.SendEmail(input, null, _options, default);
Assert.IsTrue(result.EmailSent);
}

Expand All @@ -109,15 +105,16 @@ public void SendEmailWithFileAttachment()

var attachment = new Attachment
{
AttachmentType = AttachmentType.FileAttachment,
FilePath = _filepath,
SendIfNoAttachmentsFound = false,
ThrowExceptionIfAttachmentNotFound = true
};


var Attachments = new Attachment[] { attachment };
var Attachments = new AttachmentOptions { Attachments = new Attachment[] { attachment } };

var result = SMTP.SendEmail(input, Attachments, _options, new System.Threading.CancellationToken());
var result = SMTP.SendEmail(input, Attachments, _options, default);
Assert.IsTrue(result.EmailSent);
}

Expand All @@ -132,9 +129,9 @@ public void SendEmailWithStringAttachment()
AttachmentType = AttachmentType.AttachmentFromString,
stringAttachment = fileAttachment
};
var Attachments = new Attachment[] { attachment };
var Attachments = new AttachmentOptions { Attachments = new Attachment[] { attachment } };

var result = SMTP.SendEmail(input, Attachments, _options, new System.Threading.CancellationToken());
var result = SMTP.SendEmail(input, Attachments, _options, default);
Assert.IsTrue(result.EmailSent);
}

Expand All @@ -152,9 +149,9 @@ public void TrySendingEmailWithNoFileAttachmentFound()
};


var Attachments = new Attachment[] { attachment };
var Attachments = new AttachmentOptions { Attachments = new Attachment[] { attachment } };

var result = SMTP.SendEmail(input, Attachments, _options, new System.Threading.CancellationToken());
var result = SMTP.SendEmail(input, Attachments, _options, default);
Assert.IsFalse(result.EmailSent);
}

Expand All @@ -172,9 +169,9 @@ public void TrySendingEmailWithNoCcAndBcc()
};


var Attachments = new Attachment[] { attachment };
var Attachments = new AttachmentOptions { Attachments = new Attachment[] { attachment } };

var result = SMTP.SendEmail(input, Attachments, _options, new System.Threading.CancellationToken());
var result = SMTP.SendEmail(input, Attachments, _options, default);
Assert.IsFalse(result.EmailSent);
}

Expand All @@ -192,9 +189,9 @@ public void TrySendingEmailWithNoFileAttachmentFoundException()
};


var Attachments = new Attachment[] { attachment };
var Attachments = new AttachmentOptions { Attachments = new Attachment[] { attachment } };

Assert.Throws<FileNotFoundException>(() => SMTP.SendEmail(input, Attachments, _options, new System.Threading.CancellationToken()));
Assert.Throws<FileNotFoundException>(() => SMTP.SendEmail(input, Attachments, _options, default));

}
}
Expand Down
200 changes: 0 additions & 200 deletions Frends.SMTP.SendEmail/Frends.Smtp.SendEmail/Definitions.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace Frends.SMTP.SendEmail.Definitions
{
/// <summary>
/// Attachment
/// </summary>
public class Attachment
{
/// <summary>
/// Chooses if the attachment file is created from a string or copied from disk.
/// </summary>
public AttachmentType AttachmentType { get; set; }

/// <summary>
/// Attachment from string.
/// </summary>
[UIHint(nameof(AttachmentType), "", AttachmentType.AttachmentFromString)]
public AttachmentFromString stringAttachment { get; set; }

/// <summary>
/// Attachment file's path. Uses Directory.GetFiles(string, string) as a pattern matching technique. See https://msdn.microsoft.com/en-us/library/wz42302f(v=vs.110).aspx.
/// Exception: If the path ends in a directory, all files in that folder are added as attachments.
/// </summary>
[DefaultValue("\"\"")]
[UIHint(nameof(AttachmentType), "", AttachmentType.FileAttachment)]
public string FilePath { get; set; }

/// <summary>
/// If set true and no files match the given path, an exception is thrown.
/// </summary>
[UIHint(nameof(AttachmentType), "", AttachmentType.FileAttachment)]
public bool ThrowExceptionIfAttachmentNotFound { get; set; }

/// <summary>
/// If set true and no files match the given path, email will be sent nevertheless.
/// </summary>
[UIHint(nameof(AttachmentType), "", AttachmentType.FileAttachment)]
public bool SendIfNoAttachmentsFound { get; set; }
}
}
Loading

0 comments on commit da95ecd

Please sign in to comment.