Page 1 of 1

SMTP with username and pwd

PostPosted: Mon Mar 02, 2020 4:30 pm
by Riyaz
Hi There

We are planning to use Sendgrid smtp server for Jiwa emails, example warehouse transfers, but I need to feed the username and pwd somewhere,

I have followed the instructions as per this thread viewtopic.php?f=26&t=459 , but still no luck, have different different ports too, 25, 465, etc

Kindly advise

Re: SMTP with username and pwd

PostPosted: Mon Mar 02, 2020 4:33 pm
by Riyaz
Sorry forgot attachment, I got the attached error too

Re: SMTP with username and pwd

PostPosted: Mon Mar 02, 2020 4:34 pm
by Scott.Pearce
SMTP username and password is normally stored against each user, in the Staff Maintenance form.

Re: SMTP with username and pwd

PostPosted: Mon Mar 02, 2020 4:36 pm
by Riyaz
So if I update the user I'm logged in as, will it use the same details for every email that goes out from Jiwa for all users?

Re: SMTP with username and pwd

PostPosted: Mon Mar 02, 2020 4:37 pm
by Mike.Sheen
Riyaz wrote:So if I update the user I'm logged in as, will it use the same details for every email that goes out from Jiwa for all users?


No.

Each user needs to have their own credentials entered into their staff maintenance record.

Re: SMTP with username and pwd

PostPosted: Mon Mar 02, 2020 5:32 pm
by SBarnes
Hi Riyaz

Use port 587, smtp server smtp.sendgrid.net with requires ssl set to false, we have a customer using it and those are the settings that work, you then need to fill in each user as Mike stated with a user name and password that send grid will recognise.

You can also use the Sendgrid nuget package and use the SendGridClient with an API key also to send emails.

Re: SMTP with username and pwd

PostPosted: Mon Mar 02, 2020 9:01 pm
by Riyaz
Thanks Stuart

I’ve just used 25 and works fine now, have set each user with smtp details for it to work like Mike suggested

Re: SMTP with username and pwd

PostPosted: Mon Mar 02, 2020 10:39 pm
by Mike.Sheen
Riyaz wrote:Thanks Stuart

I’ve just used 25 and works fine now, have set each user with smtp details for it to work like Mike suggested


If you actually wanted ALL users of Jiwa to use the same SendGrid account to send emails, then that is possible one of two ways:
  • Copy and modify our SMTP plugin to use a fixed set of SMTP credential (best practice here would be to have some system settings storing that)
  • Or just set configure every staff record to use the same credentials

I don't know what your use case here is, but for 99% of our customers what you've done already is what we've seen customers happy with.

And, as Stuart mentioned you can also opt to use their SendGridClient along with the API key instead - which is most likely a better practice.

That would require a custom plugin to use as the emailing mechanism instead of one of our standard ones - we currently have 3 we ship with as options - Outlook, SMTP and Office365 (and you'll see a 4th one deploy with standard Jiwa soon which is the Microsoft Graph API plugin for emailing - we're using that internally and with some select customers and it is working well) - but any of those should give you an idea of how to email using any method, as long as you can invoke a library or API via a plugin.

Re: SMTP with username and pwd

PostPosted: Tue Mar 03, 2020 6:39 am
by SBarnes
If you are going to go the SendGridClient route the following code should largely get you there, this is currently used from a Windows service in production. You will need to add embedded references for the plugin to SendGrid(version 9.10.0) and any DLLs such as NewtonSoft(Version 11.0.2) it uses to make it work. The code may work with the latest versions of both but I haven't tried that.

Code: Select all
        private static async Task SendEmailAsyncWithAttachment(string EmailTo, string Subject, string Body, byte[] Attachment, string AFileName)
        {
           
            var client = new SendGridClient("API KEY Goes Here");
            Content con = new Content("text/plain", Body);
            List<Content> cons = new List<Content>();
            cons.Add(con);
            var msg = new SendGridMessage()
            {
                From = new EmailAddress(Reader.EmailFrom, Reader.EmailFrom),
                Subject = Subject,
               PlainTextContent = Body,
                // HtmlContent = "<strong>" + Body + "</strong>"
               // Contents = cons

            };
            msg.AddTo(new EmailAddress(EmailTo, EmailTo));


            var att = new Attachment()
            {
                Content = Convert.ToBase64String(Attachment),
                //Type = AType,
                Filename = AFileName,
                //Disposition = "inline",
                //ContentId = AContentID
            };
            msg.AddAttachment(att);





            var response = await client.SendEmailAsync(msg);
        }



and

Code: Select all
        public static async Task SendEmailAsync(string EmailTo, string Subject, string Body)
        {

           
            var client = new SendGridClient("API KEY Goes Here");
            var msg = new SendGridMessage()
            {
                From = new EmailAddress(Reader.EmailFrom, Reader.EmailFrom),
                Subject = Subject,
                PlainTextContent = Body,
               // HtmlContent = "<strong>" + Body +"</strong>"
            };
            msg.AddTo(new EmailAddress(EmailTo, EmailTo));
            var response = await client.SendEmailAsync(msg);


           // return true;
        }