How to configure osgi config xml under config folder programatically?

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

30-06-2019

Hi,

I have a requirement to set osgi config properties @programatically. For instance i have created a xml file under config file(email service) with below values

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

    jcr:primaryType="sling:OsgiConfig"

    debug.email="{Boolean}true"

    from.address=""

    smtp.host="smtp.gmail.com"

    smtp.password="password"

    smtp.port="465"

    smtp.ssl="{Boolean}true"

    smtp.user="mymail@gmail.com"/>

Arun PatidarJoerg Hohsmacdonald2008

I wasnt to set all these values programatically

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,462 likes

Total Posts

3,328 posts

Correct reply

949 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,462 likes

Total Posts

3,328 posts

Correct reply

949 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

01-07-2019

I tried with as MessageGatewayService well, it is taking from address from osgi config but Name is working.

e.g.

email.setFrom("abcd.efg@gmail.com", "Arun Patidar");

aem63app-repo/HTMLEmailServlet.java at master · arunpatidar02/aem63app-repo · GitHub

I am not sure, if there is any other configuration to work above but if you really want to go with config update then you can use below  code :

-------------------------------------------------------------

Configuration configuration = configAdmin.getConfiguration("com.day.cq.mailer.DefaultMailService");

if (configuration != null) {

// get properties

Dictionary<String, Object> properties = configuration.getProperties();

Dictionary<String, Object> newProperties = properties;

// update properties

        if (properties == null) {

        newProperties = new Hashtable<String, Object>();

        }

       

        newProperties.put("smtp.user", "new user");

        newProperties.put("smtp.password","new pass");

        newProperties.put("from.address", "new from");

configuration.update(newProperties);

// send mail

// revert to old property

configuration.update(properties);

}

Answers (10)

Answers (10)

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,141 likes

Total Posts

3,167 posts

Correct reply

1,084 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,141 likes

Total Posts

3,167 posts

Correct reply

1,084 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

01-07-2019

These properties are system-wide settings. They are not supposed to be changed by a user, but are persistent defaults. If you need to change the source address of an email generated by AEM you can use the methods described by the other responses. But you should never change OSGI configurations with input provided a user.

Jörg

Avatar

Avatar
Establish
Level 6
antoniom5495929
Level 6

Likes

91 likes

Total Posts

212 posts

Correct reply

39 solutions
Top badges earned
Establish
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Establish
Level 6
antoniom5495929
Level 6

Likes

91 likes

Total Posts

212 posts

Correct reply

39 solutions
Top badges earned
Establish
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
antoniom5495929
Level 6

01-07-2019

Hi,

do you think is it possible for you to use an other approach?

E.g. I think that you could use the MailService with the default file configuration and use API in order to change the sender based on the dialog configuration.

Have a look on the following snippet:

String mydialogSender = getDialogSender();

  Email mail = new HtmlEmail();

  mail = mail.setFrom(mydialogSender);

mail.setCharset("UTF-8");

mail.setSubject(mailSubject);

mail.addTo(emailTo);

mail.setMsg( mailPattern );

mailService.send(mail);

Let us know.

Thanks,

Antonio

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,462 likes

Total Posts

3,328 posts

Correct reply

949 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,462 likes

Total Posts

3,328 posts

Correct reply

949 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

01-07-2019

You can set sender info from code by adding keys in map like below as you are using ACS Common.

No need to update osgi config

emailParams.put("senderEmailAddress","abcd@example.com");

emailParams.put("senderName","David Smith");

More info

Email API

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

01-07-2019

I am actually using acs common email service

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

01-07-2019

yeah will try them out

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

01-07-2019

thanks Arun, I'll try this out

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

01-07-2019

I tried this way but the sender mail is getting picked up from osgi config property 'smtp.user'

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

30-06-2019

author should be able to configure the from address from name in the email. These should be coming from component dialog

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

30-06-2019

i want the from.email or smtp.user to be coming from dialog.

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,141 likes

Total Posts

3,167 posts

Correct reply

1,084 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,141 likes

Total Posts

3,167 posts

Correct reply

1,084 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

30-06-2019

Why do you want to set this within Code? eMail configuration should be very static and known upfront. It's a property of the AEM instance (because it relates to the environment the application is running in) and should not be set by code.

What is your usecaes that you want to set these properties by code?