그루비 스크립트에서 전자 메일을 보내려고합니다. 아래 코드를 입력했습니다 :groovy.lang.GroovyRuntimeException - 이메일 전송시
import org.apache.commons.net.smtp.*
port = 25
org = 'mycompany.org'
client = new SMTPClient()
client.connect('<server_name>', port)
client.login()
// set sender and recipient
client.sender = "<email_address>"
client.addRecipient("<email_address>")
// create and send header information
header = new SimpleSMTPHeader("<email_address>",
"<email_address>", 'Successful build')
header.addCC("<email_address>")
header.addHeaderField('Organization', org)
writer = new PrintWriter(client.sendMessageData())
writer << header
// send body of message
writer << 'Successful build for ' + new Date()
writer.close()
client.logout()
client.disconnect()
fixture.assertEmailArrived(from: "[email protected]$org",
subject: 'Successful build')
나는 코드를 실행하기 위해 아파치의 commons-net-2.0.jar를 사용하고 있습니다.
Caught: groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.io.PrintWriter#<init>.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[class java.lang.String]
[class java.io.File]
[class java.io.Writer]
[class java.io.OutputStream]
groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.io.PrintWriter#<init>.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[class java.lang.String]
[class java.io.File]
[class java.io.Writer]
[class java.io.OutputStream]
at TestEmail.run(TestEmail.groovy:20)
오류 코드의이 부분에서 오는 것 같다 : 오류 메시지는 다음과 같습니다 나는 client.sendMessageData (을 인쇄하려고
writer = new PrintWriter(client.sendMessageData())
)와 값이 나오고 null로. 이상적으로는 Writer 객체를 나타내는 값이어야합니다. 문제를 해결하도록 도와주세요. 명령이 어떤 이유로 실패 할 경우
new PrintWriter(client.sendMessageData())
나는 sendMessageData
반환 널 생각 :
아무런 인증이 필요하지 않습니까? 'login' 메소드 호출의 결과는 무엇입니까? – Opal
나는 그것이 효과가 있다고 믿는다. 나는'System.out << client.login()'코드로 인쇄하려고 시도하고'true'를 출력합니다. 그래서 나는 그것이 작동해야한다고 생각했습니다. 그것은 null을 얻는'client.sendMessageData()'를 출력 할 때입니다. –