Questions tagged [smtpclient]

on .NET Framework , allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP)

1275 questions
278
votes
17 answers

Why do I get "'property cannot be assigned" when sending an SMTP email?

I can't understand why this code is not working. I get an error saying property can not be assigned MailMessage mail = new MailMessage(); SmtpClient client = new SmtpClient(); client.Port = 25; client.DeliveryMethod =…
Sam Stephenson
  • 5,200
  • 5
  • 27
  • 44
188
votes
5 answers

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

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…
MetaGuru
  • 42,847
  • 67
  • 188
  • 294
128
votes
6 answers

What are best practices for using SmtpClient, SendAsync and Dispose under .NET 4.0

I'm a bit perplexed on how to manage SmtpClient now that it is disposable, especially if I make calls using SendAsync. Presumably I should not call Dispose until SendAsync completes. But should I ever call it (e.g., using "using"). The scenario…
tofutim
  • 22,664
  • 20
  • 87
  • 148
124
votes
2 answers

Sending email fails when two factor authentication is on for Gmail

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 it off, the web application sends email…
user217648
  • 3,338
  • 9
  • 37
  • 61
71
votes
4 answers

How to send email using simple SMTP commands via Gmail?

For educational purposes, I need to send an email through an SMTP server, using SMTP's fundamental and simple rules. I was able to do that using smtp4dev. I telnet localhost 25 and and commands are: I want to do the same thing, using Gmail SMTP…
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
55
votes
6 answers

Send HTML email via C# with SmtpClient

How do I send an HTML email? I use the code in this answer to send emails with SmtpClient, but they're always plain text, so the link in the example message below is not formatted as such.

Welcome to SiteName. To activate your account, visit this…

user34537
46
votes
3 answers

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

I have the following code: public static void Send(this MailMessage email) { if (!isInitialized) Initialize(false); //smtpClient.SendAsync(email, ""); email.IsBodyHtml = true; Thread…
Aaron Azhari
  • 987
  • 1
  • 10
  • 24
44
votes
7 answers

C# SmtpClient class not able to send email using gmail

I'm having trouble sending email using my gmail account. I'm pulling my hair out. The same settings work fine in Thunderbird. Here's the code. I've also tried port 465 with no luck. SmtpClient ss = new SmtpClient("smtp.gmail.com",…
Razor
  • 17,271
  • 25
  • 91
  • 138
40
votes
6 answers

C# sending mails with images inline using SmtpClient

SmtpClient() allows you to add attachments to your mails, but what if you wanna make an image appear when the mail opens, instead of attaching it? As I remember, it can be done with about 4 lines of code, but I don't remember how and I can't find it…
KdgDev
  • 14,299
  • 46
  • 120
  • 156
34
votes
6 answers

SmtpClient with Gmail

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…
simonbs
  • 7,932
  • 13
  • 69
  • 115
34
votes
3 answers

System.Net.Mail creating invalid emails and eml files? Inserting extra dots in host names

It appears that .NET's SmtpClient is creating emails with an extra dot in host names if the dot was to appear at the beginning of a MIME encoded line (e.g. test.com sometimes shows up as test..com). Example code: [TestMethod] public void…
Beep beep
  • 18,873
  • 12
  • 63
  • 78
33
votes
1 answer

Sending mail via SMTP using TLS

Does anybody know of any good libraries I can use to send a mail via SMTP from Haskell? I found SMTPClient and HaskellNet. The former does not support TLS and the latter does not seem to have examples for using TLS to send an email via SMTP. Did…
Salil
  • 9,534
  • 9
  • 42
  • 56
29
votes
3 answers

SmtpClient: A connection attempt failed because the connected party did not properly respond after a period of time

While working with Email sending in C#.NET in visual studio 2008 i got the below error A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host…
DShah
  • 9,768
  • 11
  • 71
  • 127
29
votes
10 answers

How to enable SSL for SmtpClient in Web.config

Is there a way to set the EnableSSL from the web.config? I could set this property in code, but that wouldn't work for the Simple Mail Web Event and other classes that uses the default Smtp Server. Any ideas?
holiveira
  • 4,445
  • 9
  • 36
  • 39
29
votes
2 answers

Asp.Net Identity 2.0 - How to Implement IIdentityMessageService to do Async SMTP using SmtpClient?

I've implemented a simple EmailService for Asp.Net Identity 2.0 (via the IIdentityMessageService interface. public class EmailService : IIdentityMessageService { public Task SendAsync(IdentityMessage message) { // convert…
Mr. T
  • 3,892
  • 3
  • 29
  • 48
1
2 3
84 85