SendMail()

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

SendMail()

Post by Fig »

I would like to use SendMail() from my firm network.
I got the ip mail serveur adress of my firm, port, a genuine email adress from my company and its password.

Is it the good way to use it ?
Because It doesn't go through... :cry:

Do you have any clue or do I need any other information ? (I have a doubt about the ip adress instead of the smtp one...)

Code: Select all

Result = SendMail(0, "192.168.3.5", 587, #PB_Mail_Asynchronous,"email@my-firm.com","password")
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
firace
Addict
Addict
Posts: 902
Joined: Wed Nov 09, 2011 8:58 am

Re: SendMail()

Post by firace »

Try using the #PB_Mail_UseSSL flag.

Works for me:

Code: Select all

SendMail(0, "smtp.gmail.com", 587,  #PB_Mail_UseSSL, sender_login$, sender_password$)
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: SendMail()

Post by Olli »

@fig

I note firace replaced also immediate strings with string variables for both login name and password : it is very important not to use immediate strings for this critical points. This should be noticed in the manual...
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: SendMail()

Post by BarryG »

What do you mean, Olli?
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: SendMail()

Post by Fig »

thank you all for your answers... Olliver, I followed your advise and use string variable instead or direct string.
I tried with #PB_Mail_UseSSL without anysuccess.

FIrst thing first:
Could someone confirm me the IP instead of the "smtp" is a proper way to go ?

If so, the mail server probably need to accept request from my program like a mailclient. I may need to parameter specificaly the mail server... ? (specify like outlook.exe....)
Does anyone has experience with internal mailserver ? Doesn't it need to know the name of program allowed to access it as client ?
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
spikey
Enthusiast
Enthusiast
Posts: 586
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: SendMail()

Post by spikey »

Fig wrote:Could someone confirm me the IP instead of the "smtp" is a proper way to go ?
I tested this to make sure. SendMail() is quite happy to accept a server IP's address rather than a qualified domain name - if that's what you mean? (There's not directly such a thing as an "SMTP address" the way you allude in your first post - SMTP is not an addressing protocol, it's a data transfer protocol).
Fig wrote:If so, the mail server probably need to accept request from my program like a mailclient. I may need to parameter specificaly the mail server... ? (specify like outlook.exe....)
Yes to the first bit, but that shouldn't be an issue - it's what mail servers are meant to do. How is outlook.exe specifiying the mail server? Outlook is a client program. I don't follow your thinking there!
Fig wrote:Doesn't it need to know the name of program allowed to access it as client ?
Not specifically as far as the SMTP protocol is concerned, however other things may be interfering - see below... As long as the submission is on the right port and conforms to the SMTP message protocol properly it should be accepted by the server. (Note however that this is not the same as delivering a message.)

There are a few things:-
1) Your code fragment is not nearly complete enough. The problem could be caused elsewhere in your code - by a missing recipient address for example.
2) Check the value of MailProgress() after the send. I'm guessing the result is #PB_Mail_Error but an actual confirmation of this would eliminate some guessing.
3) Is your login really of the form "email@my-firm.com"? Just because your email address looks like that doesn't necessarily mean your server login does, it might depend on which mailserver your firm is using...
4) Check the logs on the mail server. Did the connection get established? If so, was the message accepted? Either way, it might report what the problem with the message was. If there is no trace of the message but other messages are logged from your usual email client on the machine normally then this may suggest a connection problem rather than an SMTP problem.
5) Does your firm use desktop firewall, anti-virus or other security software? If so, does it whitelist software? It's possible to configure firewalls, for example, to disallow access to the SMTP ports for applications that aren't standard. For example outlook.exe could be whitelisted and others would be blacklisted - this would then automatically exclude your program. Check the security software logs on the sending machine.
6) Does your firm have security or spam scanning software on its email server? This might be declining to accept your message on the grounds it looks like spam. Check the logs on the security software.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: SendMail()

Post by Marc56us »

Result = SendMail(0, "192.168.3.5", 587,
First of all, test with Telnet

Code: Select all

telnet 192.168.3.5 387
If no welcome banner (220 ... ): this is not the good ip or port.
type 'quit' to quit

Search "SMTP by telnet" if you don't know commands to sent.
If telnet is not installed on your windows, install it (accessories) or use PuTTY

:wink:
Last edited by Marc56us on Wed Nov 11, 2020 3:32 pm, edited 1 time in total.
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: SendMail()

Post by Fig »

5) Does your firm use desktop firewall, anti-virus or other security software? If so, does it whitelist software? It's possible to configure firewalls, for example, to disallow access to the SMTP ports for applications that aren't standard. For example outlook.exe could be whitelisted and others would be blacklisted - this would then automatically exclude your program. Check the security software logs on the sending machine.
That's what I tried to say...

Ok, thank you for all these clues, I'll have to spend some time with my firm's adminstrator until it properly works.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
NicTheQuick
Addict
Addict
Posts: 1226
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: SendMail()

Post by NicTheQuick »

There are also different password encryption techniques. And Purebasic only seems to offer plaintext passwords. I am also not sure if it can decide between SSL/TLS and StartTLS.
For example I am not able to send mails through my own server listening on port 587 with StartTLS and plaintext passwords.
In the log of my server I see this:

Code: Select all

Nov 11 18:16:34 hxxxxxxx postfix/submission/smtpd[3370]: lost connection after UNKNOWN from unknown[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]
Nov 11 18:16:34 hxxxxxxx postfix/submission/smtpd[3370]: disconnect from unknown[xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx] unknown=0/4 commands=0/4
In most cases this just means that a client tries to connect with an fully encrypted connection instead of first talking plaintext and then upgrade the connection to TLS (StartTLS).

Looks like there is another flag missing for SendMail. Maybe it should be called #PB_MAIL_UseStartTLS or something like this. Nearly every mail server I know uses StartTLS instead of raw SSL/TLS.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply