SMTP help needed

rfresh

Well-Known Member
Licensed User
Longtime User
I'm trying to send myself an email using the smtp server at gmail, but I never get the email. Below is my code.

B4X:
SMTP1.Initialize("smtp.gmail.com", 465, "myname@gmail.com", "mypw", "SMTP")
SMTP1.To.Add ("my_email_address")
SMTP1.Subject = "Subject"
SMTP1.Body = "Body"
SMTP1.AddAttachment(File.DirRootExternal,"1.jpg")
SMTP1.Send

I verified the image file is there where it should be.

Thanks...
 

mcohen82

New Member
Licensed User
Longtime User
Cannot send email with attachment.

I am able to send email using the following code as long as the "Mailer.AddAttachment" line is commented out. If the Mailer.AddAttachment line is in then no email goes through. Also, I never see any results from my "SMTP_MessageSent", whether or not the email sends successfully.

Sub btnSend_Click
Dim Mailer As SMTP
Mailer.Initialize("smtp.gmail.com", 465, "example@gmail.com", "password", "SMTP_MessageSent")
Mailer.UseSSL = True
Mailer.To.Add("SendTo@gmail.com")
Mailer.Subject = ("Mail Test")
Mailer.Body = "This is the message body."
' ***** Mailer.AddAttachment(File.DirDefaultExternal & newfolder.ToString, "zipped.zip")
Mailer.Send
End Sub

Sub SMTP_MessageSent(Success As Boolean)
Log(Success)
If Success Then
ToastMessageShow("Message sent successfully", True)
Else
ToastMessageShow("Error sending message", True)
Log(LastException.Message)
End If
End Sub


Thank you for the help!
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
sending mail using Gmail error

hi,

something is not working right - i am trying to send email using Gmail, with or without attachment it generates error: java.net.SocketTimeoutException

why? what is wrong with my code? is there any other way to do it?

another thing is that it takes very long time...

thanks,

this is my code:


Sub SMTP_MessageSent(Success As Boolean)
Dim s As String

Log(Success)
If Success Then
ToastMessageShow("Message sent successfully", True)
Else
ToastMessageShow("Error sending message", True)
s = LastException.Message
Log(s)
End If
End Sub

Sub SMTP_SendMail(sTO As String, sCC As String, sBCC As String, mSubj As String, mBody As String)

Dim Mailer As SMTP

Mailer.UseSSL = True

Mailer.Initialize("smtp.gmail.com", 465, SMTP_UserName, SMTP_Password, "SMTP")


Mailer.To.Add(sTO)
Mailer.CC.Add(sCC)
Mailer.BCC.Add(sBCC)

Mailer.Subject = mSubj
Mailer.Body = mBody

'Mailer.AddAttachment(fPath, fName)

Mailer.Send

End Sub
 
Last edited:
Upvote 0

walterf25

Expert
Licensed User
Longtime User
SMTP Code

Hi there can you post the code that worked for you, i'm having the same issue, i keep getting the same error, timedout error!

Thanks,
Walter
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
just follow the link in my post - it will take you to the russian page but it is in normal code so it will be easy to read - i also can't read any russian
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…