Jose Bredariol
asked on
How to Send Email from VB2008 with attachment thru gmail account ?
How can i send an Email with attach thru Gmail account
have a look at http://geekswithblogs.net/aymanfm/archive/2006/03/09/71868.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm receiving an error with this code :
Dim Msg As New MailMessage
Dim smtp As New SmtpClient("smtp.gmail.com ", 587)
smtp.Credentials = New Net.NetworkCredential("acc ount@gmail .com", "passw")
smtp.EnableSsl = True
Msg.Sender = New MailAddress("account@gmail .com", "ALIAS")
Msg.To.Add(New MailAddress("Toemail@hotma il.com"))
Msg.Subject = "subject"
Msg.Body = "body"
Msg.Attachments.Add(New Attachment("C:\M00758.txt" ))
Msg.From = Msg.Sender
smtp.Send(Msg) - error coul'd send message
MsgBox("done")
What's wrong ?
Thanks
Dim Msg As New MailMessage
Dim smtp As New SmtpClient("smtp.gmail.com
smtp.Credentials = New Net.NetworkCredential("acc
smtp.EnableSsl = True
Msg.Sender = New MailAddress("account@gmail
Msg.To.Add(New MailAddress("Toemail@hotma
Msg.Subject = "subject"
Msg.Body = "body"
Msg.Attachments.Add(New Attachment("C:\M00758.txt"
Msg.From = Msg.Sender
smtp.Send(Msg) - error coul'd send message
MsgBox("done")
What's wrong ?
Thanks
which error?
Sorry, I saw your error.
Can you provide the exact exception message?
Have you tried port 465?
Can you provide the exact exception message?
Have you tried port 465?
ASKER
I've tried with 465 too, but I'm receiving "Time Limited Exceed"
have you tried the exact code from http://geekswithblogs.net/aymanfm/archive/2006/03/09/71868.aspx
ASKER
I tried, but I've got the same error.
mail.From = New MailAddress("xxxxx@gmail.c om", "SBA")
mail.To.Add("yyyyyy@hotmai l.com")
mail.Subject = "XSubject"
mail.Body = "XMessage"
mail.IsBodyHtml = True
mail.ReplyTo = New MailAddress("any email")
smtp.Host = "smtp.gmail.com"
smtp.Port = 587 - tried with 25 and 465 too
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredenti al("accoun tgmail@gma il.com", "pass")
smtp.Send(mail) - Error here
Any other Ideia ? Thanks
mail.From = New MailAddress("xxxxx@gmail.c
mail.To.Add("yyyyyy@hotmai
mail.Subject = "XSubject"
mail.Body = "XMessage"
mail.IsBodyHtml = True
mail.ReplyTo = New MailAddress("any email")
smtp.Host = "smtp.gmail.com"
smtp.Port = 587 - tried with 25 and 465 too
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredenti
smtp.Send(mail) - Error here
Any other Ideia ? Thanks
I just tried your code on port 587 and it is working fine for me (I removed the ReplyTo because it is of no use)
The other thing I can think of are:
-invalid credentials
-invalid "From"
-Your firewall is blocking you
The other thing I can think of are:
-invalid credentials
-invalid "From"
-Your firewall is blocking you
>The other thing I can think of are:
-invalid credentials
-invalid "From"
-Your firewall is blocking you<
Invalid credentials gets you a 5.5.1 not authorized. On gmail, the from address is taken from the credentials for security (to prevent sending spam) and a firewall problem should result in a "Unable to connect to the remote server" type of error.
It would definitely help to know the exact exception we are dealing with. Wrap your code in a try catch like this, and post back what exception is printed in the immediate window.
-invalid credentials
-invalid "From"
-Your firewall is blocking you<
Invalid credentials gets you a 5.5.1 not authorized. On gmail, the from address is taken from the credentials for security (to prevent sending spam) and a firewall problem should result in a "Unable to connect to the remote server" type of error.
It would definitely help to know the exact exception we are dealing with. Wrap your code in a try catch like this, and post back what exception is printed in the immediate window.
Try
mail.From = New MailAddress("xxxxx@gmail.com", "SBA")
mail.To.Add("yyyyyy@hotmail.com")
mail.Subject = "XSubject"
mail.Body = "XMessage"
mail.IsBodyHtml = True
mail.ReplyTo = New MailAddress("any email")
smtp.Host = "smtp.gmail.com"
smtp.Port = 587 '- tried with 25 and 465 too
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential("accountgmail@gmail.com", "pass")
smtp.Send(mail) '- Error here
Catch ex As SmtpException
Debug.WriteLine(ex)
End Try
ASKER
Look to see if it's what you want.
Thanks
-------------------------- ---------- ---------- ---------- -
System.Net.Mail.SmtpExcept ion: Falha ao enviar email. ---> System.Net.WebException: Impossível conectar-se ao servidor remoto ---> System.Net.Sockets.SocketE xception: Nenhuma conexão pôde ser feita porque a máquina de destino as recusou ativamente 209.85.133.109:587
em System.Net.Sockets.Socket. DoConnect( EndPoint endPointSnapshot, SocketAddress socketAddress)
em System.Net.Sockets.Socket. InternalCo nnect(EndP oint remoteEP)
em System.Net.ServicePoint.Co nnectSocke tInternal( Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- Fim do rastreamento de pilha de exceções internas ---
em System.Net.ServicePoint.Ge tConnectio n(PooledSt ream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
em System.Net.PooledStream.Ac tivate(Obj ect owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
em System.Net.PooledStream.Ac tivate(Obj ect owningObject, GeneralAsyncDelegate asyncCallback)
em System.Net.ConnectionPool. GetConnect ion(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
em System.Net.Mail.SmtpConnec tion.GetCo nnection(S tring host, Int32 port)
em System.Net.Mail.SmtpTransp ort.GetCon nection(St ring host, Int32 port)
em System.Net.Mail.SmtpClient .GetConnec tion()
em System.Net.Mail.SmtpClient .Send(Mail Message message)
--- Fim do rastreamento de pilha de exceções internas ---
em System.Net.Mail.SmtpClient .Send(Mail Message message)
em CET2008.Frmemail.Button2_C lick(Objec t sender, EventArgs e) na E:\Junior\SISTEMAS\CET_vb6 \CET2008.N ET\Frmemai l.vb:linha 80
Thanks
--------------------------
System.Net.Mail.SmtpExcept
em System.Net.Sockets.Socket.
em System.Net.Sockets.Socket.
em System.Net.ServicePoint.Co
--- Fim do rastreamento de pilha de exceções internas ---
em System.Net.ServicePoint.Ge
em System.Net.PooledStream.Ac
em System.Net.PooledStream.Ac
em System.Net.ConnectionPool.
em System.Net.Mail.SmtpConnec
em System.Net.Mail.SmtpTransp
em System.Net.Mail.SmtpClient
em System.Net.Mail.SmtpClient
--- Fim do rastreamento de pilha de exceções internas ---
em System.Net.Mail.SmtpClient
em CET2008.Frmemail.Button2_C
have you seen http://www.systemnetmail.com/faq/5.2.aspx
and maybe you can get even more details by using this execption handler: http://www.systemnetmail.com/faq/5.aspx
and maybe you can get even more details by using this execption handler: http://www.systemnetmail.com/faq/5.aspx
Sounds to me like Gmail may be blocking you. They do have some limitations in number of emails sent per time period and things like that to limit spammers. Log in to Gmail via the web interface and see if any of your messages were sent, and if you received any bouncebacks or terms of service messages.
ASKER
Now It's working. Thanks to all