B4J Question Send un/styled email to Hotmail (B4Xemail Library) [SOLVED]

ThRuST

Well-Known Member
Licensed User
Longtime User
Hi everyone !
I found an example how to send an email and tested it. It works well with Gmail (after messing with the security settings).
However when sending to Hotmail it won't get through. Can anyone provide a working example how you got this to work with Hotmail?
Bonus question: Can you style this by sending HTML format with fonts and colors, multiple lines, if so how to do that?

To find the original post click here

References:
Link to how to use Gmail SMTP server

Link to how to use Hotmail SMTP server

Usage
B4X:
SendMail("My test mail", "Hello from B4X!", "yourmail@hotmail.com")

Code
B4X:
Public Sub SendMail(Subject As String, Body As String, MailTo As String)

    SMTP.Initialize("mailserver", portnumber ,"example@hotmail.com" , "password", "smtp")
    SMTP.Subject = Subject
    SMTP.Body = Body
    SMTP.To.Add(MailTo)
    SMTP.StartTLSMode = True
    SMTP.Send
    Wait For SMTP_MessageSent(Success As Boolean)
    Log(Success)
    If Success Then
        Log("Message sent successfully")
    Else
        Log("Error sending message")
        Log(LastException.Message)
    End If

End Sub

EDIT:
With help from the community members I put together a little source code example how to send email to anywhere including Hotmail using plain text and an alternative method to send HTML formatted text.

Here's the result as plain text email (to Hotmail)
1628538220861.png

Here's the result as Html formatted email (To Hotmail of course - what did you expect :cool: )

Send an email source code:
v0.3 Plain text only
v0.4 Plain text/HTML formatting (both included as optional)

UPDATE: Available is now also B4Xemail Library. Latest version is v0.4 that corresponds to the source code examples.
This was made using a non-GUI project. It supports both default/html email messages.
You can pre-define your custom html messages or use in-line html code when you pass the message in the parameters.
Hope you find my email library useful :)?
 

Attachments

  • 1628461166724.png
    1628461166724.png
    29.8 KB · Views: 297
  • Send an email v0.3.zip
    187.8 KB · Views: 310
  • Send an email v0.4.zip
    202.3 KB · Views: 391
  • B4Xemail library v0.4.zip
    31.5 KB · Views: 342
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
@OliverA i do have an outlook.com account (hotmail) and there is no app specific password like gmail or yahoo, afaik you can with your regular passwords.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Enrique Gonzalez R How to open post 587? I use Google Chrome. Should it be added there? I have put together a small email template app that you can download and modify to your liking. It's available for download in post #1. Whatever solutions we come up with I can update it in the app. That should be useful.
All the common mail servers are added, yay :)?
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
@Enrique Gonzalez R How to open post 587? I use Google Chrome. Should it be added there? I
are you in windows?
this is for inbound, you do it for outbound.

and no, google chrome has nothing to do with smtp.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
I just updated my email app to v0.2. It need

B4X:
Wait For SMTP_MessageSent(Success As Boolean)

to work so log should work now.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Enrique Gonzalez R I follwed the guide and allowed port 587. I unchecked "public" as adviced on the page.
What avout doing this programmically? It will make life easier (at least I want to think so) :cool:
However email still won't get through to Hotmail. I used one's email server since it works to send to other places with my domain.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
What avout doing this programmically? It will make life easier
you just have to do it once, and you can forget about it,
the uncheck public is only if you are not on a public net. if you are on a public net and unchek it, the rule will not apply.

Also this is your dev pc, in linux servers you usually do that with one line.

However email still won't get through to Hotmail
thats bad. i already checked my outlook account to see if there was some per app password but nothing.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
If anyone found a way to make email work to Hotmail from my example source or alternative code and from all advice please post it here.
The source code is really useful to experiment with, so enjoy finding the solution :)?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Ok to wrap this up as a solution I can say that I tested to send to hotmail using one.com's mailserver. The alternative is baked into the source code example app.
I noticed that mail from my domain was forwarded into a subfolder in Hotmail (outlook online), so incoming mail weren't visible in the inbox.
However I tried it with another Hotmail account and it showed up correctly, so obviously it works to send to hotmail now.
It might have been that @Enrique Gonzalez R advice to open port 587 did it. I have to disable it again to confirm it.
This is important to know since users might not be able to use B4J email functions if Windows blocks port 587.
Please post your own experiences to make debugging easier. Thanks for helping me to crack this nut ✨?‍♂️?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Btw, what about my bonus question, to send HTML formatted messages... anyone? it ain't over till it's over ?
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Bonus question: Can you style this by sending HTML format with fonts and colors, multiple lines, if so how to do that?
you create an html template. after that wrap it as a b64 encoded body
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
I've implemented it in my source code example (v0.4). My question how to send email to Hotmail and anywhere else has been answered and and now works well, yay.

Thanks everyone for solving this.

[✨SOLVED✨] ⚡?‍♂️?
 
Upvote 0
Top