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
5
votes
1 answer

Is it okay to pass a System.Net.Mail.MailMessage object around on a delegate in C#?

I have made a small SmtpSender class which handles the sending of an Smtp MailMessage object. When the message has been sent or failed to send I raise a delegate that contains a 'response' object that has the original MailMessage that the user was…
David Honess
  • 153
  • 1
  • 1
  • 5
5
votes
3 answers

The specified string is not in the form required for an e-mail address. when sending an email

Trying to send email to multiple recipient using below code gives me this error: The specified string is not in the form required for an e-mail address. string[] email = {"emailone@gmail.com","emailtow@gmail.com"}; using (MailMessage mm = new…
jack
  • 75
  • 1
  • 1
  • 4
5
votes
1 answer

linked resource does not come as inline image C#

I have written below code to embed image in the mail which is being sent from my c# code. But when i check the mail, i get image like an attachment and not as an inline image. (Gmail) AlternateView htmlBodyView = null; string htmlBody =…
Vikas Kottari
  • 495
  • 2
  • 10
  • 24
5
votes
2 answers

.NET 4.5 SMTP Client Dot Stuffing Issue when Delivering to Pickup Directory

Hoping someone will be able to help out with this, I've been looking round and I can't seem to find an answer anywhere. I'm creating a mail message using that will be delivered to a specified pickup directory, this code has been used numerous times…
Jak Hammond
  • 1,460
  • 3
  • 11
  • 24
5
votes
1 answer

How to Properly Add CSS in a MailMessage

I'm writing some HTML to a MailMessage.Body and would like to include some CSS to format fonts, tables, etc. I'm having trouble getting the final HTML to be formed properly. For example: public static void CreateMessageWithMultipleViews(string…
tommy_o
  • 3,640
  • 3
  • 29
  • 33
5
votes
5 answers

Using MailMessage to send emails in C#

I am experiencing some problems sending emails with MailMessage. I have two email accounts, (account1@gmail.com, and account2@gmail.com) and I would like account2 to send an email to account one at a button click event. This is what I have but it's…
Zac Voicheq
  • 93
  • 1
  • 1
  • 7
5
votes
1 answer

Accented characters not showing up

I have a requirement where an email is sent to an user and he can directly reply to the email and that email's content gets posted in his account. Problem is accented characters are not showing up properly when user posts the content from his email.…
Jack
  • 7,433
  • 22
  • 63
  • 107
4
votes
2 answers

MVCMailer SendAsync and deleting attachments

I'm having trouble getting MVCMailer to delete attachments after sending an email asynchronously. I can't figure out what to do to dispose of the message to free up processes attached to the message attachments. Following the instructions here.... …
James South
  • 10,147
  • 4
  • 59
  • 115
4
votes
1 answer

C# MailMessage AlternateViews displaying HTML tags

I am using MailMessage in C# to send out a HTML email. The code I am using is as follows MailMessage msg = new MailMessage(); AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Test Message", null,…
newidforu
  • 41
  • 1
  • 3
4
votes
1 answer

Sending Mails with attachment in C#

I need to send a mail including the exception details (Yellow Screen Of Death) as attachment. I could get the YSOD as follows: string YSODmarkup = lastErrorWrapper.GetHtmlErrorMessage(); if (!string.IsNullOrEmpty(YSODmarkup)) { Attachment YSOD…
Anjana
  • 1,447
  • 5
  • 23
  • 33
4
votes
1 answer

Sending an email with the header return-path using windows virtual mail server

I'm trying to send an email message using the .NET MailMessage class which can also have the return-path header added so that any bounces come back to a different email address. Code is below: MailMessage mm = new MailMessage( new…
John_
  • 2,931
  • 3
  • 32
  • 49
4
votes
1 answer

MailMessage in HTML with AlternateView in Text not working

Can anyone explain why this code is not working: async Task Main() { using (var smtpClient = new SmtpClient(@"127.0.0.1", 25)) { smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; var from = new…
JuChom
  • 5,717
  • 5
  • 45
  • 78
4
votes
4 answers

HTML email not displaying correctly

i have a strange problem with sending HTML mail in c#. Basically i am trying to email myself the weather every morning and I begin by downloading the weather in HTML markup from an ftp site. After obtaining the source file i then read it into a…
Grant
  • 11,138
  • 32
  • 94
  • 140
4
votes
2 answers

How to suppress email validation when using SmtpClient and MailMessage

When sending out emails using the SmtpClient and a MailMessage (.net 3.5) the "To" email address(es) get validated prior to sending. I've got a big stack of email addresses which have a dot (.) before the at-sign, causing a FormatException when you…
Mats
  • 14,902
  • 33
  • 78
  • 110
4
votes
2 answers

Is there a way to serialize a .Net MailMessage object

I am trying to write a proc that will take in as a parameter a MailMessage object, and the split it apart to store the subject, body, to addresses, from address, and attachments (the hard part) in a database so the email can be sent at some point in…
Matt Dawdy
  • 19,247
  • 18
  • 66
  • 91
1 2
3
22 23