Questions tagged [mailmessage]

The MailMessage class can be considered the foundation class of the System.Net.Mail namespace.

The MailMessage class can be considered the foundation class of the System.Net.Mail namespace.

Instances of the MailMessage class are used to construct e-mail messages that are transmitted to an SMTP server for delivery using the SmtpClient class.

The sender, recipient, subject, and body of an e-mail message may be specified as parameters when a MailMessage is used to initialize a MailMessage object. These parameters may also be set or accessed using properties on the MailMessage object.

The MailMessage class also allows an application to access the headers collection for the message using the Headers property. While this collection is read-only (a new collection can not be set), custom headers can be added to or deleted from this collection.

344 questions
9
votes
5 answers

C# SMTP email sending code fails for Yahoo Mail but works fine for other servers, can anyone help?

I am using this code to send an SMTP email via the yahoo SMTP server, it is for a personal project I am writing. using System.Net.Mail; using System.Net; SmtpClient theClient = new SmtpClient("smtp.mail.yahoo.com",…
David Honess
  • 153
  • 1
  • 1
  • 5
9
votes
2 answers

Elegant way to serialize a MailMessage object in .NET

I'm currently looking at serializing a MailMessage object in C# and although there are a couple of variations of an example on the net, they serialize to binary which kind of misses the point IMO. My approach is that I'd like to serialize a…
PaulV
  • 195
  • 1
  • 9
8
votes
3 answers

Erroneous email receiver display when using German umlauts and a comma in name

Using the MailMessage class in .NET 4, I found an issue today that I'm unable to resolve so far. Please see the following code: using (var message = new MailMessage()) { message.From = new MailAddress(@"uwe.keim@gmail.com", "Uwe Keim"); …
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
8
votes
2 answers

MailMessage Attachment filename with accents

I'm trying to send HTML e-mails with attached Excel filenames. It all worked well until I neded to send messages whose attachment name contains accented letters :-( Every workaround I've tried failed miserably. Original code: var attachment = new…
Serge Wautier
  • 21,494
  • 13
  • 69
  • 110
7
votes
2 answers

Convert MailMessage to MemoryStream in .net core

I am using the .Net Core 1.2 with Amazon SES(SimpleEmail) to send the Emails(Raw Emails). Below is the working code version we have used in .net framework 4.5: public MemoryStream ConvertMailMessageToMemoryStream(MailMessage message) { …
7
votes
2 answers

Sending to multiple Email addresses but displaying only one C#

I am using the SmtpClient in C# and I will be sending to potentially 100s of email addresses. I don't want to have to loop through each one and send them an individual email. I know it is possible to only send the message once but I don't want the…
dagda1
  • 26,856
  • 59
  • 237
  • 450
7
votes
3 answers

Is it possible to capture the "Message-ID" of an email message sent with SmtpClient?

Using the SmtpClient and MailMessage classes in .NET to send emails through a local mail server (hMailServer), I currently found no way to get the Message-ID header value of a sent message. The idea behind I'm trying to programmatically track…
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
6
votes
2 answers

System.Net.Mail and MailMessage not Sending Messages Immediately

When I sent a mail using System.Net.Mail, it seems that the messages do not send immediately. They take a minute or two before reaching my inbox. Once I quit the application, all of the messages are received within seconds though. Is there some sort…
mservidio
  • 12,817
  • 9
  • 58
  • 84
6
votes
1 answer

SMTP mail with encrypt permission Outlook

When I send a mail with the option "Encrypt only" in Outlook I receive a mail like this : Currently, I use SMTPClient with MailMessage to send mail : MailMessage message = new MailMessage(); message.From = from; MailAddress to = new…
Antoine V
  • 6,998
  • 2
  • 11
  • 34
6
votes
4 answers

How do I send an email message from my C# application?

This is the code I wrote: MailMessage mail = new MailMessage("test@gmail.com", "me@myurl.com"); mail.Subject = "This is a test!!"; mail.Body = "testing..."; SmtpPermission connectAccess = new…
adeena
  • 4,027
  • 15
  • 40
  • 52
6
votes
4 answers

Embedding background images in an e-mail

I'm trying to use an embedded image in an e-mail as the background image, i've got the following code to embed it: LinkedResource backgroundLink = new LinkedResource("..\\..\\background.gif"); backgroundLink.ContentId =…
Chris
  • 131
  • 1
  • 1
  • 5
6
votes
2 answers

.NET SmtpClient: Is there a way to make sure that all emails resolve prior to sending MailMessage?

I am using SmtpClient to send an email to multiple recipients. As employees leave the company, their email addresses become invalid. Since their email addresses remain in our database until deleted manually, trying to send an email to them causes…
oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
6
votes
2 answers

Properly disposing resources used by SmtpClient

I have a C# service that runs continuously with user credentials (i.e not as localsystem - I can't change this though I want to). For the most part the service seems to run ok, but ever so often it bombs out and restarts for no apparent reason…
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
5
votes
3 answers

Code analysis complains I'm not disposing objects. What is wrong here?

Consider this code private MailMessage GetMailMessageFromMailItem(Data.SystemX.MailItem mailItem) { var msg = new MailMessage(); foreach (var recipient in mailItem.MailRecipients) { var…
katit
  • 17,375
  • 35
  • 128
  • 256
5
votes
2 answers

Building a Email Sender Service

I have a couple of web applications which all utilize sending emails whether it be by contact form, or some kind of notification updates etc. The problem I have found is that there isn't really any way to track the emails which are being sent from…
Dalbir Singh
  • 2,629
  • 3
  • 26
  • 29
1
2
3
22 23