Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join us at the Cloud Data and Analytics Tour! REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Email sending not working

Why this this function not working?

function sending()
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Subject"
objMessage.From = "test1@gmail.com"
objMessage.To = "test2@gmail.com"

objMessage.TextBody = "Body"

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"


objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername ") ="test1@gmail.com"

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword ") ="password"

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

objMessage.Configuration.Fields.Update

objMessage.Send
end function

1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

For what it's worth, here is the code I'm using with GMail. Tested few minutes ago and working:

Sub SendGMail()

' Object creation

Set objMsg = CreateObject("CDO.Message")

Set msgConf = CreateObject("CDO.Configuration")

' Server Configuration

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user@gmail.com"

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1

msgConf.Fields.Update

' Email

objMsg.To = "user@gmail.com"

objMsg.From = "fromuser@domain.com"

objMsg.Subject = "Test send with Gmail account"

objMsg.HTMLBody = "HTML/Plain text message."

objMsg.Sender = "Mr. Name"

Set objMsg.Configuration = msgConf

' Send

objMsg.Send

' Clear

Set objMsg = nothing

Set msgConf = nothing

End Sub

Hope that helps.

Miguel Angel Baeyens

BI Consultant

Comex Grupo Ibérica

View solution in original post

32 Replies
Miguel_Angel_Baeyens

Hi,

You need to add the "Use SSL" as required by Google

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1 ' True will work as well


Hope that helps.

Not applicable
Author

Thanks, but i still have a problem:

530 5.5.1

http://mail.google.com/support/bin/answer.py?answer=14257

Login and password from gmail account is correct.

Miguel_Angel_Baeyens

For what it's worth, here is the code I'm using with GMail. Tested few minutes ago and working:

Sub SendGMail()

' Object creation

Set objMsg = CreateObject("CDO.Message")

Set msgConf = CreateObject("CDO.Configuration")

' Server Configuration

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user@gmail.com"

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1

msgConf.Fields.Update

' Email

objMsg.To = "user@gmail.com"

objMsg.From = "fromuser@domain.com"

objMsg.Subject = "Test send with Gmail account"

objMsg.HTMLBody = "HTML/Plain text message."

objMsg.Sender = "Mr. Name"

Set objMsg.Configuration = msgConf

' Send

objMsg.Send

' Clear

Set objMsg = nothing

Set msgConf = nothing

End Sub

Hope that helps.

Miguel Angel Baeyens

BI Consultant

Comex Grupo Ibérica

View solution in original post

Not applicable
Author

Thank you. It is working. Yes

chooco_co
Partner
Partner

hi all,

how about we send gmail to yahoo? can work?

i already tried if i set the sender from one domain (exchange) to another email (recepient) on the same domain, it can work, but if the recepient on yahoo or different domain. it can't work..

thanks,

Marco

Miguel_Angel_Baeyens

Hello Marco,

It's working fine for me from GMail to Yahoo mail. Anyway, check that the line

objMsg.From = "fromuser@domain.com"

Is properly configured.

If you are using your Exchange server instead of the gmail one, you should check your anti-relay and anti-spam rules, but it doesn't make much sense to me since most of the time mails are sent to people in different domains.

Hope that helps.

Miguel Angel Baeyens

BI Consultant

Comex Grupo Ibérica

chooco_co
Partner
Partner

Hello Miguel,

i try from your script but got an error message "The transport failed to connect to the server."

sub SendEmail(attachment)

          Dim strMailTo

          Dim ObjSendMail

          Set objSelected = ActiveDocument.Fields("EMAILIDS").GetPossibleValues

          if objSelected.Count = 0 then

                    msgbox ("No e-mail reciepient selected")

                    exit sub

          else

                    varSubject = "Report"

                    varTextBody = "Please find report attached"

                    varAttachment = attachment

                    Set ObjSendMail = CreateObject("CDO.Message")

                    ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

                    ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "172.16.10.63"

                    ObjSendMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

                    ObjSendMail.Configuration.Fields.Update

                    ObjSendMail.AddAttachment varAttachment

                    For i = 0 to objSelected.Count-1

                              ObjSendMail.To = objSelected.item(i).Text

                              ObjSendMail.Subject = varSubject

                              ObjSendMail.From = "admin@qlikview.co.id"

                              ObjSendMail.TextBody = varTextBody

                              ObjSendMail.Send

                    next

                    Set ObjSendMail = Nothing

          end if

end sub

this's my code for email exchange..

Miguel_Angel_Baeyens

Hello Mario,

If you take a look at your configuration fields, you are only using three (sendusing, smtpserver and smtpserverport). In my example code above (that is the one I'm using for testing) there are few more, and along them are the user logged into the smtp server (sendusername, sendpassword), what it seems is one of the issues you are having.

Use them in your code with yoour configuration and try again.

Hope that helps.

Miguel Angel Baeyens

BI Consultant

Comex Grupo Ibérica

Not applicable
Author

Hello Miguel,

                i am getting the same msg  "The transport failed to connect to the server."

i am using exactly same code what you have used in your correct answer.

thanks

Harleen