Passeword Email

I can't send an e-mail, can you help me?I tried via gmail, I tried via outlook
No description
4 Replies
Buddy
Buddy12mo ago
Do you get any errors?
V0FBU1VM
V0FBU1VM12mo ago
I believe the issue is the port. I while ago I hade the same issue. System.Net.Mail.SmtpClient does not support Implicit SSL on port 465 I believe.
![ 𝐒𝐀𝐇𝐌𝐄𝐑𝐀𝐍 ] Enes
I get the mail could not be sent error
V0FBU1VM
V0FBU1VM12mo ago
@![ 𝐒𝐀𝐇𝐌𝐄𝐑𝐀𝐍 ] Enes I use a newer package called Mailkit. It has also been recommended by microsoft. Here is an example:
using MailKit.Net.Smtp;
using MediatR;
using MimeKit;
using Quotifyr.Commands;

namespace Quotifyr.Handlers;

public class SendEmailHandler : IRequestHandler<MailMessageCommand>
{
public async Task Handle(MailMessageCommand request, CancellationToken cancellationToken)
{
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress("Quotifyr", SecretSettings.EmailAddress));
mimeMessage.To.Add(new MailboxAddress(request.UserName, request.To));
mimeMessage.Subject = request.Subject;

var bodyBuilder = new BodyBuilder();
if (request.IsHtml)
bodyBuilder.HtmlBody = request.Body;
else
bodyBuilder.TextBody = request.Body;

mimeMessage.Body = bodyBuilder.ToMessageBody();

using var client = new SmtpClient();
await client.ConnectAsync(SecretSettings.SmtpServer, SecretSettings.SmtpPort,
cancellationToken: cancellationToken);
await client.AuthenticateAsync(SecretSettings.EmailAddress, SecretSettings.EmailAddressPassword,
cancellationToken);
await client.SendAsync(mimeMessage, cancellationToken);
await client.DisconnectAsync(true, cancellationToken);
}
}
using MailKit.Net.Smtp;
using MediatR;
using MimeKit;
using Quotifyr.Commands;

namespace Quotifyr.Handlers;

public class SendEmailHandler : IRequestHandler<MailMessageCommand>
{
public async Task Handle(MailMessageCommand request, CancellationToken cancellationToken)
{
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress("Quotifyr", SecretSettings.EmailAddress));
mimeMessage.To.Add(new MailboxAddress(request.UserName, request.To));
mimeMessage.Subject = request.Subject;

var bodyBuilder = new BodyBuilder();
if (request.IsHtml)
bodyBuilder.HtmlBody = request.Body;
else
bodyBuilder.TextBody = request.Body;

mimeMessage.Body = bodyBuilder.ToMessageBody();

using var client = new SmtpClient();
await client.ConnectAsync(SecretSettings.SmtpServer, SecretSettings.SmtpPort,
cancellationToken: cancellationToken);
await client.AuthenticateAsync(SecretSettings.EmailAddress, SecretSettings.EmailAddressPassword,
cancellationToken);
await client.SendAsync(mimeMessage, cancellationToken);
await client.DisconnectAsync(true, cancellationToken);
}
}
Want results from more Discord servers?
Add your server