如何在服务器端存储邮件密码? [英] How to store mail password on server side?

查看:125
本文介绍了如何在服务器端存储邮件密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Weblogic 10.0上部署的应用程序发送电子邮件.我尝试将邮件会话属性放在服务器端.诸如mail.hostmail.debug之类的属性可以正常工作.但是,如何配置密码?现在,我将其保存在spring配置文件中:

I need to send e-mails from my application that is deployed on Weblogic 10.0. I try to put mail session properties on server side. Properties like mail.host or mail.debug work OK. But how do I configure password? Now I have it in spring configuration file:

<bean id="mailSender"
    class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="session" ref="mailSession"/>
    <property name="username" value="myLogin"></property>
    <property name="password" value="myPassword"></property>
</bean>     
<bean id="alertsMailSession" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>mail/mainSession</value>
    </property>     
    <property name="resourceRef"> 
        <value>true</value>
    </property>
</bean>

我尝试了mail.smtp.password属性,但是它不起作用. Sun文档说密码没有属性(尽管在某些示例中我已经看到mail.smtp.password).那我该怎么办呢?是否可以在服务器上而不是在应用程序中配置登录名/密码信息?

I tried mail.smtp.password property, but it doesn't work. Sun documentation says there is no property for password (although I've seen mail.smtp.password in some examples). So how should I do it? Is it possible to have login/password information configured on server, not in application?

编辑
大家都建议一些属性文件.我不要我的应用程序服务器上有一个邮件会话.我通过JNDI参加了本次会议.我可以将主机配置为用于发送邮件等等.但我不能在那里输入密码.它不起作用.我希望所有配置都可以通过Weblogic控制台完成.如何实现?

EDIT
All of you suggest some properties files. I don't want them. I have a mail session on my application server. I get this session by JNDI. I can configure there host to use to send mails and so on. But I can't put there password. It doesn't work. I want all of the configuration to be done by Weblogic console. How to achieve that?

推荐答案

当我使用websphere atm时,不确定这是否对weblogic有帮助,但我想也可以在weblogic中起作用:

Not sure whether this will help in weblogic, as I work with websphere atm, but I'd imagine would work in weblogic as well:

在您的春季上下文中设置您的用户名和密码,如下所示:

set-up your username and password in your spring context as such:

<bean id="mailSender" 
    class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="session" ref="mailSession"/>
<property name="username">
    <jee:jndi-lookup jndi-name="config/mail/username" resource-ref="true"/>
</property>
<property name="password">
    <jee:jndi-lookup jndi-name="config/mail/password" resource-ref="true"/>
</property>

并在您的web.xml中添加以下内容:

and add the following in your web.xml:

<env-entry>
    <env-entry-name>config/mail/username</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value></env-entry-value>
</env-entry>
<env-entry>
    <env-entry-name>config/mail/password</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value></env-entry-value>
</env-entry>

Spring将在Web应用程序环境中查找用户名和密码的值. weblogic管理控制台应允许您配置环境条目,并因此配置用户名和密码.请注意,您可能必须重新启动应用程序才能使更改生效,因为这些更改仅在spring上下文启动时才加载,但是,邮件服务器更改的设置是相当大的更改,因此重新启动不会是那个错.

Spring will lookup the values for username and password from the web-application environment. The weblogic admin console should allow you to configure the environment entries and therefore the username and password. Note, you'll probably have to restart the application in order for the changes to take effect as they'll only be loaded when the spring context starts, however, the settings for the mail server changing are a pretty major change, so a restart wouldn't be that amiss.

这篇关于如何在服务器端存储邮件密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆