smtpclient

Confused with the SmtpClient.UseDefaultCredentials Property

两盒软妹~` 提交于 2019-11-27 17:41:29
问题 In my MVC4 application, I am using the SmtpClient to send out email via Gmail's smtp.gmail.com SMTP server. I have configured my Web.Config file with the following settings: <system.net> <mailSettings> <smtp deliveryMethod="Network"> <network enableSsl="true" defaultCredentials="false" host="smtp.gmail.com" port="587" userName="xxMyUserNamexx@gmail.com" password="xxMyPasswordxx" /> </smtp> </mailSettings> </system.net> The method that uses the SmtpClient and sends an email message looks like:

Sending email fails when two factor authentication is on for Gmail

做~自己de王妃 提交于 2019-11-27 17:14:14
I am using my Gmail account and smtp.gmail.com inside my web application to test and send email. when two factor authentication is ON for my Gmail account, it fails to send the email, however when I turn off two factor authentication for my Gmail account, the web application sends email successfully. Appreciate any kind of advice. Create a custom app in you Gmail security settings. 1. Log-in into Gmail with your account 2. Navigate to https://security.google.com/settings/security/apppasswords 3. In 'select app' choose 'custom', give it an arbitrary name and press generate 4. It will give you

C# SMTP fails to authenticate on Outlook.com, port 587. “The server response was: 5.7.1 Client was not authenticated”

↘锁芯ラ 提交于 2019-11-27 15:45:15
问题 I'm attempting to send automated emails (genuinely required business reason - not spam!). Code similar to that below used to work with another mail service provider but the customer has moved to "outlook.com" and they're now getting: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated Surely this (C#) code should work: private void Send_Click(object sender, EventArgs e) { MailMessage message = null; try

smtpclient “ failure sending mail”

牧云@^-^@ 提交于 2019-11-27 14:43:34
here is my code for(int i = 0; i < number ; i++) { MailAddress to = new MailAddress(iMail.to); MailAddress from = new MailAddress(iMail.from, iMail.displayName); string body = iMail.body; string subject = iMail.sub; oMail = new MailMessage(from, to); oMail.Subject = subject; oMail.Body = body; oMail.IsBodyHtml = true; oMail.Priority = MailPriority.Normal; oMail.Sender = from; s = new SmtpClient(smtpServer); if (s != null) { s.Send(oMail); } oMail.Dispose(); s = null; } this loops sends over 60,000 email. but my problem i am getting " failure sending mail" in some of the email some times 5000

.NET Best Method to Send Email (System.Net.Mail has issues)

扶醉桌前 提交于 2019-11-27 13:56:03
问题 This seems to be pretty straight forward. I need to send email from some ASP.NET applications. I need to do this consistently without strange errors and without CPU utilization going through the roof. I'm not talking about mass emailing, just occasional emails. System.Net.Mail appears to be horribly broken. The SmtpClient does not issue the Quit command (it may be because Microsoft(R) is not interested in following specifications), therefore a connection is left open. Therefore, if someone

Do we need to dispose or terminate a thread in C# after usage?

大兔子大兔子 提交于 2019-11-27 13:28:40
问题 I have the following code: public static void Send(this MailMessage email) { if (!isInitialized) Initialize(false); //smtpClient.SendAsync(email, ""); email.IsBodyHtml = true; Thread mailThread = new Thread(new ParameterizedThreadStart( (o) => { var m = o as MailMessage; SmtpClient client= new SmtpClient("smtpserveraddress"); client.Send(m); })); mailThread.Start(email); I want the mail sending to be done in the background without interfering with the main thread. I do not care when it is

SmtpClient with Gmail

安稳与你 提交于 2019-11-27 11:55:12
I'm developing a mail client for a school project. I have managed to send e-mails using the SmtpClient in C#. This works perfectly with any server but it doesn't work with Gmail. I believe it's because of Google using TLS. I have tried setting EnableSsl to true on the SmtpClient but this doesn't make a difference. This is the code I am using to create the SmtpClient and send an e-mail. this.client = new SmtpClient("smtp.gmail.com", 587); this.client.EnableSsl = true; this.client.UseDefaultCredentials = false; this.client.Credentials = new NetworkCredential("username", "password"); try { //

How to set username and password for SmtpClient object in .NET?

强颜欢笑 提交于 2019-11-27 11:09:31
I see different versions of the constructor, one uses info from web.config, one specifies the host, and one the host and port. But how do I set the username and password to something different from the web.config? We have the issue where our internal smtp is blocked by some high security clients and we want to use their smtp server, is there a way to do this from the code instead of web.config? In this case how would I use the web.config credentials if none is available from the database, for example? public static void CreateTestMessage1(string server, int port) { string to = "jane@contoso

How to check MailMessage was delivered in .NET?

£可爱£侵袭症+ 提交于 2019-11-27 07:32:51
问题 Is there a way to check if SmtpClient successfully delivered an email? SmtpClient.Send() does not appear to return anything other than an exception. So if the method completes is it safe to assume the email will be successfully sent to the appropriate email box? My code is below: MailMessage emailMessage = new MailMessage(); emailMessage.Subject = SubjectText; emailMessage.IsBodyHtml = IsBodyHtml; emailMessage.Body = BodyText; emailMessage.From = new MailAddress(Settings.Default.FromEmail

How to send an e-mail with C# through Gmail

怎甘沉沦 提交于 2019-11-27 07:30:00
I am getting an error when trying to send an e-mail through my web service. I have tried enabling access to less secure apps disabling 2-step verification and logging into the account via a web browser. None of the solutions on SO have worked for me. I am still getting: Error: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. What can I do to fix this issue? namespace EmailService { public class Service1 : IService1 { public string SendEmail(string inputEmail, string subject,