I have built an email client app that was suppose allow users to read/receive their emails, send out emails with Flutter Web.
The Flutter web receives and send emails via an API I wrote using ASP.NET Core 5.0 Web API. I'm using Mailkit in my ASP's API. Below was the Send & Receive method:
Send()
public async Task Send(EmailMessage email)
{
var message = new MimeMessage();
message.To.AddRange(email.toAddresses.Select(x => new MailboxAddress(x.Name, x.Address)));
message.From.AddRange(email.fromAddresses.Select(x => new MailboxAddress(x.Name, x.Address)));
message.Subject = email.Subject;
var builder = new BodyBuilder();
builder.HtmlBody = email.Body;
message.Body=builder.ToMessageBody();
using (var smtp = new SmtpClient())
{
smtp.Connect("smtp.gmail.com", 587, false);
smtp.Authenticate("<*gmail username*>@gmail.com", "<*gmail password*>");
await smtp.SendAsync(message);
smtp.Disconnect(true);
}
}
ReceiveEmail()
public async Task<List<EmailMessage>> ReceiveEmail(int maxCount = 5)
{
using(var emailClient = new Pop3Client())
{
emailClient.Connect("pop.gmail.com", 995, true);
emailClient.Authenticate("<*gmail username*>@gmail.com", "<*gmail password*>");
emailClient.GetMessageCount();
List<EmailMessage> emails = new List<EmailMessage>();
for(int i=0;i<emailClient.Count && i<maxCount; i++)
{
var message =await emailClient.GetMessageAsync(i);
var emailMessage = new EmailMessage
{
Body = !string.IsNullOrEmpty(message.HtmlBody) ? message.HtmlBody : message.TextBody,
Subject = message.Subject
};
emailMessage.toAddresses.AddRange(message.To.Select(x => (MailboxAddress)x).Select(x => new EmailAddress { Address = x.Address, Name = x.Name }));
emailMessage.fromAddresses.AddRange(message.From.Select(x => (MailboxAddress)x).Select(x => new EmailAddress { Address = x.Address, Name = x.Name }));
emails.Add(emailMessage);
}
return emails;
}
}
EmailMessage.cs
public class EmailMessage
{
public EmailMessage()
{
toAddresses = new List<EmailAddress>();
fromAddresses = new List<EmailAddress>();
}
public List<EmailAddress> toAddresses { get; set; }
public List<EmailAddress> fromAddresses { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
}
EmailAddress.cs
public class EmailAddress
{
public string Name { get; set; }
public string Address { get; set; }
}
As you can see, my API runs using Gmail's smtp & POP3 server. It runs. No problem. I can post the input data and send out the email via the API and GET all the emails in the inbox via the ReceiveEmails()
But now the case was to use Zimbra, instead of Gmail, as the email service provider. And I really find all over the Web, but no hit, on solutions or any issues discussing, related on implementing this.
So, if someone knows. Please. How to enable Zimbra to allow external email client app to use its services: Send out emails via its SMTP and receive emails via its POP3? Same like what I did with Gmail?
Note: I have installed Zimbra Open Source 8.8.5 and configured it in my Ubuntu 18.04.6 server. And there is an account: admin@mail.privacy.com, there, when I access my Zimbra via http://:7071