有人可以帮我解决这个问题。
我试图使用某些数据类型,例如SMTSession,MailMessage,MailRecipient。
但它不起作用。
这是代码。
&SMTPSession.Host = 'smtp.gmail.com'<br>
&SMTPSession.Port = 465<br>
&SMTPSession.Authentication = 1<br>
&SMTPSession.UserName = 'XXXX@gmail.com'<br>
&SMTPSession.Password = 'password'<br>
&SMTPSession.Secure = 1 <br>
&SMTPSession.Sender.Address = 'XXXX@gmail.com'<br>
&SMTPSession.Sender.Name = 'OtherName'<br>
&MailRecipient.Address = 'XXXX@hotmail.com'<br>
&MailRecipient.Name = 'Name'<br>
&MailMessage.Subject = 'Subject'<br>
&MailMessage.Text = 'text'<br>
&MailMessage.To.Add(&MailRecipient)<br>
&SMTPSession.Login()
if &SMTPSession.ErrCode <> 0
&SMTPSession.Send(&MailMessage)
&SMTPSession.Logout()
endif
Genexus Evolution 3升级2,.Net环境,Web
答案 0 :(得分:0)
答案 1 :(得分:0)
代码似乎很好。 与我所做的唯一区别在于我写了&amp; error =&amp; SMTPSession.Login()
您使用的Gmail帐户未启用两个步骤验证?
答案 2 :(得分:0)
您的代码完全正确,您只是在发送前错过了状态检查,
&SMTPSession.Login()
if &SMTPSession.ErrCode = 0 // 0 = OK
&SMTPSession.Send(&MailMessage)
&SMTPSession.Logout()
else
//Msg(&SMTPSession.ErrDescription) // to see what kind of error
endif
对于我来说,我使用的是Gmail SMTP,端口为587
答案 3 :(得分:0)
为了从 GX 程序发送邮件,您必须在发件人 Google 帐户中激活允许安全性较低的应用程序的选项。