c# - SMTP server does not respond to `SmtpClient` connection attempt. How do I fix this? -
this question has reply here:
sending email in .net through gmail 20 answersi tried write code sending email .net. have far:
mailmessage mail service = new mailmessage("mymailaddress@yahoo.com", address); mail.subject = subject; mail.body = body; client.host = "smtp.gmail.com"; client.port = 587; client.send(e); the problem next exception:
unhandled exception: system.net.mail.smtpexception: failure sending mail.
system.net.webexception: unable connect remote server.
system.net.sockets.socketexception: connection effort failed because connected party did not respond after period of time, or established connection failed because connected host has failed respond 173.194.66.109:587
try this:
using system.net; using system.net.mail; // ... mailaddress mafrom = new mailaddress("<address>", "<display_name>"); mailaddress mato = new mailaddress("<address>", "<display_name>"); const string spassword = "<password>"; const string ssubject = "<subject>"; const string sbody = "<body>"; new smtpclient { host = "smtp.gmail.com", port = 587, enablessl = true, deliverymethod = smtpdeliverymethod.network, usedefaultcredentials = false, credentials = new networkcredential(mafrom.address, spassword) }.send(new mailmessage(mafrom, mato) { subject = ssubject, body = sbody }); c# .net smtpclient
No comments:
Post a Comment