Welcome! Log In Create A New Profile

Advanced

WebDev 24. EMail. The session is closed

Posted by Willy 
WebDev 24. EMail. The session is closed
February 19, 2024 01:37PM
Hello,

I try to send mails from a webdev site.
This is the code.


PROCEDURE ZendStdMail(pcBestemmeling,pcSubject,pcHtmlText)

cMailText is string = HTMLToText(pcHtmlText)
lTerug is boolean = False

// Send an email
cSMTPServer is string = INIRead(“MAILSETTINGS”,“smtpserver”,“”,fExeDir()+“\settings.ini”)
cSMTPUser is string = INIRead(“MAILSETTINGS”,“smtpuser”,“”,fExeDir()+“\settings.ini”)
cSmtpPort is string = INIRead(“MAILSETTINGS”,“smtpport”,“”,fExeDir()+“\settings.ini”)
cSmtpPassword is string = INIRead(“MAILSETTINGS”,“smtppassword”,“”,fExeDir()+“\settings.ini”)

// Build the message
MyMessage is Email

MyMessage..ReturnReceipt = True
IF ExtractString(pcBestemmeling,1) = pcBestemmeling THEN
	Add(MyMessage..Recipient,pcBestemmeling)
ELSE // Er zitten meerdere bestemmelingen in pcBestemmeling	
	FOR EACH STRING cAdres OF pcBestemmeling
		Add(MyMessage..Bcc,cAdres)
	END
END

MyMessage..Subject = pcSubject 
MyMessage..Message = HTMLToText(cMailText)
MyMessage..HTML = pcHtmlText
MyMessage..Sender = cSMTPUser

IF cSMTPServer = "smtp.gmail.com" THEN
	IF EmailStartSMTPSession(cSMTPUser, cSmtpPassword, ...
		"smtp.gmail.com", 587, False, emailOptionSecuredTLS) = True THEN
		// Procedure used to initialize the email structure
		//Initialize_Email()
		// Sends the email
		
		IF EmailSendMessage(cSMTPUser,MyMessage) = False THEN
			Error()
			ErrorInfo()
			lTerug = False
		ELSE
			lTerug = True
		END
		
		EmailCloseSession(cSMTPUser)
	ELSE
		
	END
ELSE
	// Start a SMTP session
	MySession is emailSMTPSession
	MySession..ServerAddress = cSMTPServer
	MySession..Port = cSmtpPort
	MySession..Password = cSmtpPassword
	MySession..Name = cSMTPUser
	
	MySession.Option = optionSSL
	
	EmailStartSession(MySession)
	IF EmailSendMessage(MySession, MyMessage)
	ELSE
		Error(ErrorInfo())
	END
END


RESULT lTerug

When I test this in the WebDev developersenvironment it works fine.
When I run it on my VPS I get an error
"The session is closed"

Someone any idea what is going wrong.

Already thanks.

Willy Hermans
pao
Re: WebDev 24. EMail. The session is closed
February 19, 2024 01:44PM
Arer you using smtp.gmail.com or the other option?

Regards

Paulo Oliveira
Re: WebDev 24. EMail. The session is closed
February 20, 2024 09:47AM
Hello,

I use the other option.
pao
Re: WebDev 24. EMail. The session is closed
February 20, 2024 10:45AM
What is the resuilt of the EmailStartSession function?

If it's for sending emali why don't you use EmailStartSMTPSession ?

Regards

Paulo Oliveira
Re: WebDev 24. EMail. The session is closed
February 21, 2024 05:36PM
Willy

To help I have to ask:

1) Has this code been successful from this server in the past. Just need to know if it's something that was working and now isn't.

2) Are you relaying through another mail server or do you run your own

3) I'm assuming that no details were returned from the ErrorInfo() cause you didn't post it here.

4) Paulo's question is the first thing I would look at. Does the session connect ? / result of EmailStartSession(MySession).

You can test if you can reach the mail server, i.e. telnet to the server:port and see if you get their greeting (they should respond from the connection with a 220 and banner and wait for a response from you.)
This will at least prove you can connect to that server.

5) Once you know you have rudimentary connectivity you can then move on to authentication and the multitude of other things that you need to deal with when relaying through a SMTP server as well as determining if your code has a problem

Regards

Eric
Re: WebDev 24. EMail. The session is closed
February 23, 2024 10:14AM
SOLVED
It was a stupid thing on my part.
In the ini file I had made an exact copy of the email settings.

However, it said on the server
[Mail settings]
! smtp...
! Password
! user
...


[Mail settings]
SMTP...
Password..
user


I forgot the exclamation mark in the first mail settings. These were past values that I didn't want to throw away.

Thank you very much for the effort you made.
Willy Hermans
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: