Skip to content

Commit

Permalink
Emails, work
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron.allen authored and aaron.allen committed Mar 18, 2024
1 parent fe2aefb commit f08afe8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
24 changes: 13 additions & 11 deletions KakeysBakery.ClassLib/Services/Implementations/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,25 @@ 6. Select Generate.

public string sendEmail(string recipiantEmail, MimeMessage message)
{
try {
try
{
string senderEmail = _config["KakeysEmail"];
string senderPass = _config["EmailAppPass"];

using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);

using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);

// Note: only needed if the SMTP server requires authentication
client.Authenticate(senderEmail, senderPass);

client.Send(message);
client.Disconnect(true);
// Note: only needed if the SMTP server requires authentication
client.Authenticate(senderEmail, senderPass);
message.From.Add(new MailboxAddress("Kakey's Bakery", senderEmail));
message.To.Add(new MailboxAddress("Dear Customer,", recipiantEmail));
client.Send(message);
client.Disconnect(true);
}
return "Email Sent";
}
return "Email Sent";
}
catch
{
return "Bad Exception Happend";
Expand Down
32 changes: 19 additions & 13 deletions KakeysBakery/Components/Pages/SendEmail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,38 @@

<h3>SendEmail</h3>
<img src="images/SweetnessCupcakes.png" id="cupcake1" />
<input label="Email" @bind-value=receaverEmail/>
<button @onclick="sender">Send test email</button>
@if (isSent)
{
<p>Messesge was sent</p>
<p>@returnedMessage</p>
}


@code {
bool isSent = false;
string returnedMessage;
string? receaverEmail;
private async Task sender()
{
var message = new MimeMessage();
// message.From.Add(new MailboxAddress("Auto Emailer", SenderEmail));
// message.To.Add(new MailboxAddress("An Email in need of a Message", ReceiverEmail));
message.Subject = "Automated Message System";
if (receaverEmail is not null)
{
var message = new MimeMessage();
//message.From.Add(new MailboxAddress("Auto Emailer", SenderEmail));
// message.To.Add(new MailboxAddress("An Email in need of a Message", ReceiverEmail));
message.Subject = "Automated Message System";

message.Body = new TextPart("plain")
{
Text = @"Dear Customer,
message.Body = new TextPart("plain")
{
Text = @"Dear Customer,
This Is A test Email
This Is A test Email
-- The Bakery"
};
emailService.sendEmail("[email protected]", message);
isSent = true;
-- The Bakery"
};
returnedMessage = emailService.sendEmail(receaverEmail, message);
isSent = true;
}
await Task.CompletedTask;
}

Expand Down

0 comments on commit f08afe8

Please sign in to comment.