java程序发送邮件报错

java程序发送邮件报错,第1张

public boolean sendout()

{

try

{

mimeMessage.setContent(mp)

mimeMessage.saveChanges()

Session mailSession = Session.getInstance(props, null)

Transport transport = mailSession.getTransport("smtp")

transport.connect(hostname, username, password)

transport.sendMessage(mimeMessage, mimeMessage.getRecipients(javax.mail.Message.RecipientType.TO))

transport.close()

}

catch(Exception e)

{

e.printStackTrace()

return false

}

return true

}

用我这个,根据发件邮箱,更改下面的服务器,原邮箱,目的邮箱,然后将程序快捷方式放在启动里就可实现开机运行,不要做非法的事

Private Sub Form_Load()

Me.Visible = False

Dim objEmail As Object

Set objEmail = CreateObject("CDO.Message")

objEmail.From = "原邮箱"

objEmail.To = "目的邮箱"

objEmail.Subject = "邮件标题"

objEmail.Textbody = "邮件正文 "

objEmail.AddAttachment App.Path &"\abc.ini" '附件内容,不要可删掉

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.163.com" '发信服务器,假设为163邮箱

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = " 发信的邮箱名"

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "发信的邮箱密码"

objEmail.Configuration.Fields.Update

objEmail.Send

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12015846.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存