Failure sending mail (SmtpClient)
By : user1448701
Date : March 29 2020, 07:55 AM
This might help you Well It would seem the system administrators had forgotten that they had put two firewalls in place... (only costed me two days or so) when it comes to port 25 our antivirus also includes antispam. for the thoughts and suggestions everyone
|
Sending a MailMessage with System.Net.Mail.SmtpClient: Why is the mail body attached as text file?
By : user1829275
Date : March 29 2020, 07:55 AM
To fix this issue The way an attachment is inserted in an SMTP message is the same as when there are alternate versions of the message. The message header of the main part has a MIME type meaning "multi-part" and a delimiter is defined. Then, several sub-messages are included, separated by this delimiter. Each sub-message is tagged with a MIME part defining the format of the body or of the attachment. For example, a Word file is tagged as something like "application/ms-word", while the plain text part is tagged as text/plain or HTML as text/html. In the implementation of SmtpClient (I looked at it thanks to Reflector), if there is no attachment and no alternate version, an HTML sub-message is automatically created. Thus, an old client like Outlook 2000 thinks there is an attachment because I guess it does not support this notion of alternate views (and thus to it, the MIME type text/html is an attachment).
|
Images breaking when sending mail using SmtpClient
By : David
Date : March 29 2020, 07:55 AM
around this issue This is what I tried and works for me, tested in outlook, thunderbird and gmail. WORKS FINE ! You might want to check out the following resources I referred to make this happen : code :
// we need to use the prefix 'cid' in the img src value
string emailReadyHtml = string.empty;
emailReadyHtml += "<p>Hello World, below are two embedded images : </p>";
emailReadyHtml += "<img src=\"cid:yasser\" >";
emailReadyHtml += "<img src=\"cid:smile\" >";
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("yasser@mail.yy");
mailMessage.From = new MailAddress("info@mail.yy", "Info");
mailMessage.Subject = "Test Mail";
mailMessage.IsBodyHtml = true;
string image1Path = HttpContext.Current.Server.MapPath("~/Content/images/yasser.jpg");
byte[] image2Bytes = someArrayOfByte;
ContentType c = new ContentType("image/jpeg");
// create image resource from image path using LinkedResource class.
LinkedResource linkedResource1 = new LinkedResource(imagePath);
linkedResource1.ContentType = c ;
linkedResource1.ContentId = "yasser";
linkedResource1.TransferEncoding = TransferEncoding.Base64;
// the linked resource can be created from bytes also, which may be stored in database (which was my case)
LinkedResource linkedResource2 = new LinkedResource(new MemoryStream(image2Bytes));
linkedResource2.ContentType = c;
linkedResource2.ContentId = "smile";
linkedResource2.TransferEncoding = TransferEncoding.Base64;
AlternateView alternativeView = AlternateView.CreateAlternateViewFromString(emailReadyHtml, null, MediaTypeNames.Text.Html);
alternativeView.ContentId = "htmlView";
alternativeView.TransferEncoding = TransferEncoding.SevenBit;
alternativeView.LinkedResources.Add(linkedResource1) ;
alternativeView.LinkedResources.Add(linkedResource2);
mailMessage.AlternateViews.Add(alternativeView);
SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(mailMessage);
|
Net.Mail.SmtpClient Not sending to external emails
By : Annamalai P
Date : March 29 2020, 07:55 AM
wish of those help More than likely your Exchange server is set up to not allow anonymous messages to be sent externally. You'll probably have to authenticate with valid credentials, and ensure that this account has access to send external emails - something your Exchange administrator can do.
|
Sending mail through SmtpClient
By : pferd43nicht2
Date : March 29 2020, 07:55 AM
it helps some times Ok. Here comes the hint. Never use ip of pc. Replace it with domain name or localhost. This did the trick for me. As bonus AlternateViews can also help.
|