Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 5ead5b6

Browse files
authored
Using SmtpUri to process SMTP credentials consistent with other jobs (#354)
* url decoding SMTP credentials in the orchestrator. * Switching to use SmtpUri to process SMTP settings in a consitent way across all jobs. * Removed the settings that are not used anymore.
1 parent 04f77e9 commit 5ead5b6

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/NuGet.Services.Validation.Orchestrator/Configuration/SmtpConfiguration.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ namespace NuGet.Services.Validation.Orchestrator
55
{
66
public class SmtpConfiguration
77
{
8-
public string SmtpHost { get; set; }
9-
public int SmtpPort { get; set; }
10-
public bool EnableSsl { get; set; }
11-
public string Username { get; set; }
12-
public string Password { get; set; }
8+
public string SmtpUri { get; set; }
139
}
1410
}

src/NuGet.Services.Validation.Orchestrator/Job.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,21 @@ private void ConfigureJobServices(IServiceCollection services, IConfigurationRoo
190190
{
191191
var smtpConfigurationAccessor = serviceProvider.GetRequiredService<IOptionsSnapshot<SmtpConfiguration>>();
192192
var smtpConfiguration = smtpConfigurationAccessor.Value;
193+
if (string.IsNullOrWhiteSpace(smtpConfiguration.SmtpUri))
194+
{
195+
return new MailSenderConfiguration();
196+
}
197+
var smtpUri = new SmtpUri(new Uri(smtpConfiguration.SmtpUri));
193198
return new MailSenderConfiguration
194199
{
195200
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
196-
Host = smtpConfiguration.SmtpHost,
197-
Port = smtpConfiguration.SmtpPort,
198-
EnableSsl = smtpConfiguration.EnableSsl,
201+
Host = smtpUri.Host,
202+
Port = smtpUri.Port,
203+
EnableSsl = smtpUri.Secure,
199204
UseDefaultCredentials = false,
200-
Credentials = new NetworkCredential(smtpConfiguration.Username, smtpConfiguration.Password)
205+
Credentials = new NetworkCredential(
206+
smtpUri.UserName,
207+
smtpUri.Password)
201208
};
202209
});
203210
services.AddTransient<IMailSender>(serviceProvider =>

src/NuGet.Services.Validation.Orchestrator/settings.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@
7171
"SubscriptionName": ""
7272
},
7373
"Smtp": {
74-
"SmtpHost": "",
75-
"SmtpPort": "587",
76-
"EnableSsl": "true",
77-
"Username": "",
78-
"Password": ""
74+
"SmtpUri": ""
7975
},
8076
"Email": {
8177
"GalleryOwner": "NuGet Gallery <[email protected]>",

0 commit comments

Comments
 (0)