SMTP with username and pwd

Discussions relating to plugin development, and the Jiwa API.

SMTP with username and pwd

Postby Riyaz » Mon Mar 02, 2020 4:30 pm

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
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: SMTP with username and pwd

Postby Riyaz » Mon Mar 02, 2020 4:33 pm

Sorry forgot attachment, I got the attached error too
Attachments
2020-03-02 16_32_29-Window.png
2020-03-02 16_32_29-Window.png (7.12 KiB) Viewed 4293 times
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: SMTP with username and pwd

Postby Scott.Pearce » Mon Mar 02, 2020 4:34 pm

SMTP username and password is normally stored against each user, in the Staff Maintenance form.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: SMTP with username and pwd

Postby Riyaz » Mon Mar 02, 2020 4:36 pm

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?
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: SMTP with username and pwd

Postby Mike.Sheen » Mon Mar 02, 2020 4:37 pm

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.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: SMTP with username and pwd

Postby SBarnes » Mon Mar 02, 2020 5:32 pm

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: SMTP with username and pwd

Postby Riyaz » Mon Mar 02, 2020 9:01 pm

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
Riyaz
Kohai
Kohai
 
Posts: 233
Joined: Wed Dec 02, 2015 2:05 pm
Topics Solved: 2

Re: SMTP with username and pwd

Postby Mike.Sheen » Mon Mar 02, 2020 10:39 pm

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.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: SMTP with username and pwd

Postby SBarnes » Tue Mar 03, 2020 6:39 am

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;
        }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1617
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron