我从我的管道运行一个片段,从HTML文件发送html邮件。它看起来像那样:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService spitterUserDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception{
http.formLogin().loginPage("/spitter/login").permitAll()
.and().rememberMe()
.and().authorizeRequests().antMatchers("/spitter/home").hasRole("SPITTER")
.anyRequest().permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth.userDetailsService(spitterUserDetailsService);
}
}
@Service
public class SpitterUserDetailsService implements UserDetailsService {
@Autowired
private SpitterRepository spitterRepository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
System.err.println("---------- User Details Service start -----------");
Spitter spitter = spitterRepository.findByUsername(username);
if(spitter == null){
throw new UsernameNotFoundException(username + " not found ");
}
List<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>();
authorities.add(new SimpleGrantedAuthority("ROLE_SPITTER"));
System.out.println(spitter.getUsername() + " : ROLE_SPITTER");
return new User(spitter.getUsername(), spitter.getPassword(), authorities);
}
}
@Controller
@RequestMapping("/spitter")
public class SpitterController {
@Autowired
private SpitterRepository spitterRepository;
@RequestMapping(value= "/login", method = RequestMethod.GET)
public String login(Model model){
model.addAttribute("spitter", new Spitter());
return "spitter/login";
}
@RequestMapping(value= "/loginForm", method = RequestMethod.POST)
public String login(@ModelAttribute("spitter") Spitter spitter){
System.out.println(spitter.getUsername() + " logined..");
return "redirect:home";
}
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String showRegistrationForm(Model model){
model.addAttribute("spitter", new Spitter());
return "spitter/registerForm";
}
@RequestMapping(value="/register", method = RequestMethod.POST)
public String register(@ModelAttribute("spitter") Spitter spitter){
spitterRepository.addSpitter(spitter);
return "spitter/registerSuccessfully";
}
@RequestMapping("/home")
public String hello(){
return "spitter/helloWorld";
}
}
我的问题:如何使用CID或类似方法嵌入图像文件(作为邮件的一部分)?它只适用于我将IMG标记添加到我的HTML文件,链接到我的组织实际可用的网址。我只需要将图像作为邮件的一部分嵌入。 谢谢, 尼尔
答案 0 :(得分:1)
您可以通过base64嵌入图像。转换图像here或者您想要的,然后将其输入到管道脚本中,如下所示:
(例子来自Jenkinsfile)
emailext attachmentsPattern: '%JENKINS_HOME%/changelog.xml', body: '<img src="data:image/png;base64,iVBORw0K...shortened...rkJggg==">', mimeType: 'text/html', subject: 'Look at this subject!', to: 'email@address.com'
非常重要的是,最新版本最多只能支持65535个字符,并且编码可以轻松超过该限制。
答案 1 :(得分:-1)
对于詹金斯这样的人来说,这太先进了。它并不意味着提供附加和嵌入东西的一般能力。
您应该在Python中执行此操作(传递收件人列表)并将其添加为步骤。