my code is :
Pop3Client client = new Pop3Client();
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("MyMailAccont#gmail.com", "Password");
....
error on Authenticate.eeror is:
Additional information: POP3 server did not respond with a +OK
response to the AUTH command.
my config is well.how to fix it?
gmail not work very well with pop3.
Related
Does System.Net.Mail SmtpClient support smtp server with httpS or it work only with smtp servers with http?
I mean if i pass "https//:mysmtpserver" to constructor od SmtpClient instance - it would work?
SmtpClient works with SSL, yes. You need to provide it as a property like this:
var smtpClient = new SmtpClient("smtp.gmail.com")
{
Port = 587,
Credentials = new NetworkCredential("username", "password"),
EnableSsl = true,
};
smtpClient.Send("email", "recipient", "subject", "body");
(taken from this article How to send emails from C#/.NET - The definitive tutorial)
Giving Exception on
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
this line.And Error message is
remote server returned an error 401 unauthorized
It occures only when am calling web service from other project solution...
This exception is not occuring when calling service from same project solution.
what should I do to remove this exception and get Response from Remote server??
Plz help me.
Possible solutions can be:
1) add <identity impersonate="true"></identity> in web.config
2) If you have credentials
using (client = new MyWebService())
{
var username = ConfigurationManager.AppSettings["WSUserName"]
var password = ConfigurationManager.AppSettings["WSPassword"]
client.Credentials = new NetworkCredential(username, password);
// .. and the call here ..
}
Let me know if it doesn't fix your problem.
I'm trying to convert some Python code for use in a .Net website. The code retrieves a message stored in RFC822 format and sends the message to an SMTP server again using:
mail from: blah blah
rcpt to: blah blah
data
<send the text from the RFC822 file here>
.
So no parsing of the RFC822 file is required (fortunately!). In Python this is simply:
smtp = smtplib.SMTP(_SMTPSERVER)
smtp.sendmail(_FROMADDR, recipient, msg)
where the file has been read into the variable msg. Is there an easy way to do this in C#?
The built in C# SMTP objects don't offer a way to do this, or at least I haven't found a way. They seem to be based on the principle of building up a MailMessage by providing the addresses, subject and body separately. SmtpClient has a Send(string, string, string, string) method, but again this requires a separate subject and body so I guess it constructs the RFC822 formatted message for you.
If necessary I can write my own class to send the mail. It's such a simple requirement that it wouldn't take long. However if there is a way using the standard libraries they're probably less buggy than my code.
I would recommend using MimeKit to parse the message file and then use MailKit to send via SMTP. MailKit is based on MimeKit, so they work well together and MailKit's SmtpClient is superior to System.Net.Mail's implementation.
Parsing a message is as simple as this:
var message = MimeMessage.Load (fileName);
Sending the message is as simple as these few lines:
using (var client = new SmtpClient ()) {
client.Connect ("smtp.gmail.com", 465, true);
client.Authenticate ("username", "password");
client.Send (message);
client.Disconnect (true);
}
You're right, the inbuilt stuff doesn't offer a solution for this.
My advice would be to simply write a bit of code that uses TcpClient and StreamReader / StreamWriter to interact with the SMTP server. It shouldn't need more than 50 lines of code.
This is easy to do, you need only to install MailKit and MimeKit from nuget.
Pay attention because if you don't need authentication, setting "useSsl" to false is not enough, it doesn't work. You need to set MailKit.Security.SecureSocketOptions.None
var message = MimeMessage.Load("pathToEml");
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("smtp.yourserver.yourdomain", 25, MailKit.Security.SecureSocketOptions.None); //set last param to true for authentication
//client.Authenticate("username", "password");
client.Send(message);
client.Disconnect(true);
}
I created a httplistener and it works only with localhost as a prefix. It show an error if I change it to a remote server ip.
Here's the code:
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://*:8080/"); // I need localhost replaced with remote ip
listener.Start();
while (true)
{
// Wait for a client request:
HttpListenerContext context = listener.GetContext();
// Respond to the request:
string msg = "You asked for: " + context.Request.RawUrl;
context.Response.ContentLength64 = Encoding.UTF8.GetByteCount(msg);
context.Response.StatusCode = (int)HttpStatusCode.OK;
using (Stream s = context.Response.OutputStream)
using (StreamWriter writer = new StreamWriter(s))
writer.Write(msg);
}
listener.Stop();
THis is the web client:
using (WebClient wc = new WebClient()) // Make a client request.
wc.DownloadString
("http://"my public ip"(on my router):8080/lg.txt"); //port forwarding is set
MessageBox.Show("received");
It works only if I change "my public ip" to my local ip
Any ideas?
Is your Windows Firewall on? Try disabling it and see if that helps. You may need to actually disable the Windows Firewall service (in your local services list).
Firstly, check the firewall. Perhaps more likely, though, is http.sys, which is used by HttpListener - you must make the prefix available to the account via "netsh". You can check this by running as an elevated admin account briefly - If it works it is probably a http.sys permissions issue.
I have recently purchased a new computer, and now my e-mails never get sent, and there are NEVER any exceptions thrown or anything.
Can somebody please provide some samples that work using the SmtpClient class? Any help at all will be greatly appreciated.
Thank you
Updates
Ok - I have added credentials now. And can SUCCESSFULLY SEND e-mail synchronously. But I can still not send them asynchronously.
Old:
After trying to send e-mail synchronously, I receive the following exception:
Transaction failed. The server response was:
5.7.1 <myfriend#hotmails.com>: Relay access denied.
You can send mail through Async(). How means you should follow the below code,
smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
smtpClient.SendAsync(mailMessage, mailMessage);
and, if you are using async, you need to also have the event handler like,
static void smtpClient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
//to be implemented
}
By using this, you can send Mail.
You could first try the synchronous Send method to verify that everything is setup correctly with the SMTP server and that you don't get any exceptions:
var client = new SmtpClient("smtp.somehost.com");
var message = new MailMessage();
message.From = new MailAddress("from#somehost.com");
message.To.Add(new MailAddress("to#somehost.com"));
message.Subject = "test";
message.Body = "test body";
client.Send(message);
Remark: In .NET 4 SmtpClient implements IDisposable so make sure you wrap it in a using statement.