-1

I am sending emails in my asp.net mvc application using postal. The emails are getting sent but the subject, from, cc and bcc fields are getting embedded in the email body instead of showing up in the appropriate areas.

Here are my smtp settings in web.config

<smtp from="support@domain.com" deliveryMethod="Network">
    <network host="mail.domain.com" userName="support@domain.com" password="mypassword" defaultCredentials="false" port="25" />
 </smtp>

Here is my email view

@{
    Layout = null;
 }

To: @ViewBag.To
From: support@domain.com
Bcc: support@domain.com
Subject: Welcome to @ViewBag.ClientName reporting system

Hello @ViewBag.Firstname,

Welcome.

Regards

My smtp settings in SmarterMail are correct and testing works perfectly. The problem is the formatting. How can I fix this?

The email gets sent but shows up like this:

From: support@domain.com
To:
Date: Thu, 21 May 2015 16:40:34 +0300
Subject:

--email body starts here--

From: support@domain.com

Bcc: support@domain.com

Subject: Welcome to Client Name reporting system

Hello user,

Welcome.

Regards

UPDATE: Here is the code I'm using to send the email. I'm using postal

dynamic email = new Email("WelcomeEmail");
email.To = user.Email;
email.FirstName = user.FirstName;
email.ClientName = clientName;
email.Send();
Nick Masao
  • 1,088
  • 12
  • 25

3 Answers3

2

Try like this,.

     MailMessage msg = new MailMessage();
     msg.From = new MailAddress("from mail id");
     msg.To.Add(" to mail id");
     msg.CC.Add("Mail id");
     msg.Bcc.Add("Mail id");
     msg.Subject = "enter subject";
     msg.Body="enter text";
BALA s
  • 169
  • 1
  • 9
0

Found the solution. The problem was Postal for some reason not picking up the email headers from my email view. So I set up all headers in the controller and only left the body of the email in the view. This is my updated email view.

@{
   Layout = null;
} 

Hello @ViewBag.Firstname,

Welcome.

Regards

and here is my updated setup in the controller

dynamic email = new Email("WelcomeEmail");
email.To = user.Email;
email.Bcc = "admin@domain.com";
email.From = "support@domain.com";
email.Subject = "Welcome";
email.FirstName = user.FirstName;
email.ClientName = clientName;
email.Send();
Nick Masao
  • 1,088
  • 12
  • 25
0

Something must be preventing Postal from seeing the headers.

Could there be any weird whitespace or text encoding issues? Maybe try re-saving the cshtml file with a specific encoding (e.g. UTF-8).

Without having the exact cshtml it's hard to diagnose further. Could you upload it somewhere public?

Andrew Davey
  • 5,441
  • 3
  • 43
  • 57