How to send email out with self-made email client via Zimbra's smtp?

Post feedback about our hosted demo or your local install. Tell us what you love and/or what you’d like to see added in the future.
jackshooter
Posts: 2
Joined: Fri Oct 22, 2021 7:14 am

How to send email out with self-made email client via Zimbra's smtp?

Postby jackshooter » Mon Nov 15, 2021 5:54 pm

I hoped that I did not post my question on the wrong section of Zimbra forums.

I currently have an email client app, built with Flutter web. I hoped that my email client app can send out to any email providers outside (Gmail, Outlook, etc.) and receives emails that was stored in my zimbra's Inbox: e.g. support@mail.privacy.com, someone's_name@mail.privacy.com(These are Zimbra mailboxes).

So, my email client uses ASP. NET Core 5.0 web API on sending emails which is as follows (currently using Gmail's SMTP & POP3:
Send()

Code: Select all

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("<[i]gmail username[/i]>@gmail.com", "<[i]gmail password[/i]>");
                await smtp.SendAsync(message);
                smtp.Disconnect(true);
            }

        }


ReceiveEmail() (Get from Gmail's inbox and display on my Flutter web's email client app)

Code: Select all

public async Task<List<EmailMessage>> ReceiveEmail(int maxCount = 5)
        {
            using(var emailClient = new Pop3Client())
            {
               
               
                emailClient.Connect("pop.gmail.com", 995, true);
               
               
                emailClient.Authenticate("<[i]gmail username[/i]>@gmail.com", "<[i]gmail password[/i]>");
                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;
           
        }
    }


Now the case was to use Zimbra, instead of Gmail.

So how should I perform the operation, or how should I do it, when it goes for Zimbra?


Return to “Users”

Who is online

Users browsing this forum: No registered users and 3 guests