Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 5 Jahren, 11 Monaten
Letzter Beitrag:
vor 5 Jahren, 11 Monaten
Beteiligte Autoren:
Clarion Ghost, Paulo Oliveira, Norman Bailey.pcs.crosspost, Ruben Sanchez Peña, Arie

Sending an email

Startbeitrag von Clarion Ghost am 13.07.2012 14:02

Hi there.

I would like to send an email at the end of a process. Reading the online help this is what I think I should be doing, but it doesn't work. What have I got wrong.

// Start a SMTP session
MySession is EmailSMTPSession
MySession..ServerAddress = "smtp.aol.com"
EmailStartSession(MySession)

// Build an email
MyMessage is Email
MyMessage..Sender = "test@website.co.uk"
MyMessage..Subject = "Password Change"
Add(MyMessage..Recipient,"getwebwise@aol.com") // "customer@company.com")
MyMessage..Message = "Test"," Message Line 1","Message Line 2","Message Line 3"
// Send the message
EmailSendMessage(MySession,MyMessage)

Many Thanks

Antworten:

What is the error?

I don't know if in V17 it's necessary but in previous version you have to set NbRecipient to match the number of occurences int the Recipient array.

check the sample in the help it may help you.
http://doc.windev.com/en-US/?1000003032005

von Paulo Oliveira - am 13.07.2012 16:01
I seem to be chasing my tail on this. So far the only piece of code I think I have right is:-

User is string = "getwebwise@aol.com"
Psw is string = "password"
PopServe is string = "pop.aol.com"
SMTP_serv is string = "smtp.aol.com"
UserName is string = ""

IF EmailStartSession(User,Psw,PopServe,SMTP_serv) THEN
UserName = User
ELSE
UserName = ""
Error("Unable to establish connection")
END

Now I need to build the email text (HTML I will try later) and send it to see if it works. The on line help gives a multitude of options but I cannot see how to continue.

Many thanks

von Clarion Ghost - am 14.07.2012 10:05
Hi. This works for me:

sToEmail is string = "" // First destination TO:
sOtherDestination = "" // Other destinations "," separated. is the BCC:

ElCorreo is Email
// Se envia el email
// Create the message

// Start a SMTP session
IF EmailStartSMTPSession(EmailAccount,EmailPass,EmailServer) = True THEN

// Reset the Email variables to zero
EmailReset()
// Sender of the message
Email.Sender = EmailAccount
Email.SenderAddress = EmailAccount
// Recipients of the message
Email.NbRecipient = 1
Email.Recipient[1] = sToEmail

IF sOtherDestination "" THEN
Email.NbBcc = stringcount(sOtherDestination,",") + 1
Email.Bcc = sOtherDestination
END

// Subject and content of the message
Email.Subject = "My title: "
Email.Message = sTextMessage

IF NOT EmailSendMessage(EmailAccount) THEN
Info("Error enviando email: " + ErrorInfo(errMessage))
END

// Close the SMTP session
EmailCloseSession(EmailAccount)
END

von Ruben Sanchez Peña - am 14.07.2012 12:18
Hi.

Thanks Ruben. The following code works every time. There are two particular things that I have noticed. First it is very slow to execute and second the test mode stalls and a modification is asked for.

I have missed something? Please, what am I doing wrong.

THIS WORKS
ToEmail is string = "getwebwise@aol.com" // First destination TO:
OtherDestination is string = "" // Other destinations "," separated. is the BCC:
EmailAccount is string = "getwebwise@aol.com" //Needs a fully qualified address here
EmailPass is string = "password"
EmailServer is string = "smtp.aol.com"
TextMessage is string = "Text Message - Text Message - Text Message - Text Message - Text Message - Text Message -"
//NOT USED - ElCorreo is Email
// Se envia el email
// Create the message

// Start a SMTP session
IF EmailStartSMTPSession(EmailAccount,EmailPass,EmailServer) = True THEN

// Reset the Email variables to zero
EmailReset()
// Sender of the message
Email.Sender = EmailAccount
Email.SenderAddress = EmailAccount
// Recipients of the message
Email.NbRecipient = 1
Email.Recipient[1] = ToEmail

IF OtherDestination "" THEN
Email.NbBcc = StringCount(OtherDestination,",") + 1
Email.Bcc = OtherDestination
END

// Subject and content of the message
Email.Subject = "My title: "
Email.Message = TextMessage

IF NOT EmailSendMessage(EmailAccount) THEN
Info("Error enviando email: " + ErrorInfo(errMessage))
END

// Close the SMTP session
EmailCloseSession(EmailAccount)

END



Many thanks

von Clarion Ghost - am 16.07.2012 08:31
If it's for webdev you can try the asynchronous mode to speed up your code.

http://doc.windev.com/en-US/?3032025&name=emailstartsmtpsession-function

von Paulo Oliveira - am 16.07.2012 09:56
HI

This code works perfectly with one exception. On completion of the run an error is shown in the left hand band (an arrow) and the Information Dialogue presents "Test is currently run". What the error is doesn't appear to display?

Any ideas please?

ToEmail is string = "getwebpower@aol.com" // First destination TO:
OtherDestination is string = "getwebwise@aol.com" // Other destinations "," separated. is the BCC:
EmailAccount is string = "getwebwise@aol.com" //Needs a fully qualified address here
EmailPass is string = "Password"
EmailServer is string = "smtp.aol.com"
TextMessage is string = "Text Message - Text Message - Text Message - Text Message - Text Message - Text Message -"
//NOT USED - ElCorreo is Email
// Se envia el email
// Create the message

// Start a SMTP session
IF EmailStartSMTPSession(EmailAccount,EmailPass,EmailServer) = True THEN //,emailSynchronous, emailOptionSecuredTLS) = True THEN

// Reset the Email variables to zero
EmailReset()
// Sender of the message
Email.Sender = EmailAccount
Email.SenderAddress = EmailAccount
// Recipients of the message
Email.NbRecipient = 1
Email.Recipient[1] = ToEmail

IF OtherDestination "" THEN
Email.NbBcc = StringCount(OtherDestination,",") + 1
Email.Bcc = OtherDestination
END

// Subject and content of the message
Email.Subject = "My title: "
Email.Message = TextMessage

IF NOT EmailSendMessage(EmailAccount) THEN
Info("Error enviando email: " + ErrorInfo(errMessage))
END

// Close the SMTP session
EmailCloseSession(EmailAccount)

END

von Clarion Ghost - am 17.07.2012 08:22
Ian, looks like a breakpoint you set before, on a line which doesn't exists anymore (most probably because you have less lines now than before).
There's a button to remove all breakpoints. Try that.

von Arie - am 17.07.2012 08:52
Hi Arie,

Thanks for that. I think you are right, the breakpoint button is showing that one exists where there is none. I have now tried what you have suggested but it hasn't made any difference.

I then shut down and restarted WebDev and the problem seems to have gone away. I am suspecting a bug?

Many Thanks

von Clarion Ghost - am 17.07.2012 09:43
Doesn't AOL use a port of 587 for SMTP transfers? You will have to check and include this in the code.

IF nSecureport=0 THEN
Sessionresult = EmailStartSMTPSession(username,ServerAddress)
ELSE
Sessionresult = EmailStartSMTPSession(username,mypassword,ServerAddress,nSecureport)
END
IF Sessionresult 0 THEN
MESSAGE("Attempting to send")
Email.NbRecipient = 1
Email.Recipient[1] = recipient
Email.NbAttach = 0
Email.NbBcc = 0
Email.Subject = SubjectText
Email.Message = MessageText
Email.SenderAddress = SenderAddress

IF NOT EmailSendMessage(username)
Error(EmailMsgError(Email.Error))
END
EmailCloseSession(username)

username is whatever you use in Outlook etc.

The book is OK but the 5.5 manuals were better than the current versions.

Norman

Message forwarded from pcsoft.us.windev

von Norman Bailey.pcs.crosspost - am 18.07.2012 06:44
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.