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: 311
  • Send an email v0.3.zip
    187.8 KB · Views: 324
  • Send an email v0.4.zip
    202.3 KB · Views: 412
  • B4Xemail library v0.4.zip
    31.5 KB · Views: 355
Last edited:

ThRuST

Well-Known Member
Licensed User
Longtime User
@Erel As you can see, for this example I am using my mailserver at one.com who runs my domain at Duologic.se.
For simplicity I use them instead of Gmail. This works well to email my mail at one.com and also Gmail.
But somehow the message won't go trough to Hotmail even though log says successfully sent.
However the inbox don't show anything new. I really want to be able to send mail to hotmail. Thanks!

usage
B4X:
SendMail("Testmail", "Hi! This is a testmail sent to Hotmail.", "privatemail@hotmail.com")

code
B4X:
Public Sub SendMail(Subject As String, Body As String, MailTo As String)
   
    SMTP.Initialize("send.one.com", 587 ,"contact@domain.com" , "mypassword", "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

Log
Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
true
Message sent successfully
 
Last edited:
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
I found a discussion forum at Stack overflow about this but I am still trying to make this work.

See the page here
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
You mean like this?

B4X:
SendMail("Testmail", "Hi! This is a testmessage to Hotmail.", "mailsomeone@hotmail.com")

B4X:
SMTP.Initialize("smtp-mail.outlook.com", 587 ,"contact@domain.com" , "mypasssword", "smtp")

Log
1628516721461.png


Perhaps some of all the other community members can contribute with their settings since there's many combos here.
What mail servers worked and so on. This would be very appreciated. If anyone manages to email to/from Hotmail please post your solutions.
I used another mailserver at one.com just to try to send to Hotmail but that didn't work so I'm outa options.
 
Last edited:
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
The last parameter says just "smtp" is this correct? The page I found advice this

1628517301563.png
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Enrique Gonzalez Thanks. I tried your example and this is what happened. Do you notice any errors?
I'm trying to understand this. The first parameter is the mailserver which must be tied to Hotmail, Gmail, Office365?
This is why I wanted you to post your initialization string. But I assume it is a sensitive matter. This is why I am the only one posting it :)

B4X:
SendMail("Testmail", "Hi! This is a testmail to Hotmail.", "myprivate@hotmail.com")

B4X:
SMTP.Initialize("smtp.office365.com", 587 ,"contact@domain.com" , "mypassword", "smtp")

1628523337727.png
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Note: With some email services (aol, yahoo) you have to generate a password that is application specific. You than use your user ID and the special password to email. Otherwise, emailing does not work
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@OliverA Sure I've read about this in Gmail. One can apply a special "App password" for less secure custom apps. However I never carried through with this method
since it wasn't what I wanted anyway.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
However I never carried through with this method
since it wasn't what I wanted anyway.
With some services, such as yahoo, if you don't use their app/their website, you have to use an app password. No clue about Hotmail, I'm just relaying my experience
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top