Question
· Apr 29, 2018

How to send out a sample email to yourself and not get a 6031 error?

Hello !   I am still trying to get the sample email working on my computer.  I am getting the below error.   I have tried a number of things and researching it on the net.  I am not sure what I am doing wrong.

Below is a sample class that I have been testing.  

Class email.test Extends %Persistent

{

// set myval= ##class(Package.Class).Method(Args)

// set myval= ##class(email.test).XSendSimpleMessage("")

ClassMethod SendSimpleMessage(server As %Net.SMTP) As %List

{

  Set server=##class(%Net.SMTP).%New()

  Set server.smtpserver="Smtp.aol.com"

  //HotPOP SMTP server uses the default port (25)

  Set server.port=25

  //Create object to carry authentication

  Set auth=##class(%Net.Authenticator).%New()

  Set auth.UserName="dsterngast"

  Set auth.Password="???????"

  Set server.authenticator=auth

  Set server.AuthFrom=auth.UserName  

 Set msg = ##class(%Net.MailMessage).%New()

 Set From=server.authenticator.UserName

Set:From="" From="dsterngast@aol.com"

Set msg.From = From

 Do msg.To.Insert("noman2105@aol.com")

//Do msg.Cc.Insert("yyy@yyy.com")

//Do msg.Bcc.Insert("zzz@zzz.com")

Set msg.Subject="Unique subject line here "_$H

Set msg.IsBinary=0

Set msg.IsHTML=0

Do msg.TextData.Write("This is the message.")

 Set status=server.Send(msg)

If $$$ISERR(status) {

   Do $System.Status.DisplayError(status)

   Write server.Error

   Quit ""

}

Discussion (4)0
Log in or sign up to continue

Some ISPs block port 25, see the SMTP server specs for other ports you can use (465, 587, etc).

Code below has worked for me in the past.

Tom Fitzgibbon | gototomATg...l.com

-------------------------------------------------------------------------------------------------------

SendMail(Message,SendTo,Subject) ;send mail

s s=##class(%Net.SMTP).%New()

s auth=##class(%Net.Authenticator).%New() ; use default auth

s auth.UserName="user@domain.com"

s auth.Password="xxxxxxxx"

s s.authenticator=auth

s s.smtpserver="smtpout.secureserver.net"

s s.timezone="Local"

s s.port="80" ;for secureserver

s m=##class(%Net.MailMessage).%New()

s m.Charset="iso-8859-1"

s m.From="person@domain.com"

Send ;where to?

d m.To.Insert(SendTo)

;subject

s m.Subject = Subject

d m.TextData.Write(Message)

s status=s.Send(m)

d m.%Close()

d auth.%Close()

q status

SMTP servers can have different requirements (port, SSL level, etc). You have read AOL SMTP requirements? Sometimes it requires some fiddling.

From Lifewire: Enter these SMTP settings to send outgoing email through to your AOL Mail account from any email program.

  • Incoming Mail Server: imap.aol.com
  • SMTP Outgoing Server Address: smtp.aol.com. Set the port to 587
  • SMTP Username: "user@aol.com" (or @love.com, @games.com or @verizon.net)
  • SMTP password. The password you use to log in to AOL Mail

Thanks for your suggestion and help.  Sorry for not get back to you sooner.   I have applied the changes and I get the following error.  I am not sure whether  incoming mail server,  imap.aol.com, applies.  I did not see that being used in your code.

The following is a modified version of your code that I am testing.

ZDHS9 ;
 ; From Lifewire: Enter these SMTP settings to send outgoing email through to your AOL Mail account from any email program.
 ; Incoming Mail Server: imap.aol.com
 ; SMTP Outgoing Server Address: smtp.aol.com. Set the port to 587
 ; SMTP Username: "user@aol.com" (or @love.com, @games.com or @verizon.net)
 ; SMTP password. The password you use to log in to AOL Mail

 s x=$$SendMail("testmessage","dsterngast@aol.com","test") w !,x
 Do $System.Status.DisplayError(x)
    Write s.Error
 q
SendMail(Message,SendTo,Subject) ;send mail
 s s=##class(%Net.SMTP).%New()
 s auth=##class(%Net.Authenticator).%New() ; use default auth
 s auth.UserName="user@aol.com"  ;"dsterngast@aol.com" ;"user@aol.com" ; "dsterngast@aol.com"
 s auth.Password="?????????"
 s s.authenticator=auth
 s s.smtpserver="Smtp.aol.com" ;"imap.aol.com"  ;"imap.aol.com"              ;"Smtp.aol.com"
 s s.timezone="Local"
 s s.port=587 ;for secureserver
 s m=##class(%Net.MailMessage).%New()
 s m.Charset="iso-8859-1"   ;set m.Charset="iso-8859-1"
 s m.From="dsterngast@aol.com"
Send ;where to?
 d m.To.Insert(SendTo)
 ;subject
 s m.Subject = Subject
 d m.TextData.Write(Message)
 s status=s.Send(m)
 d m.%Close()
 d auth.%Close()
 q status