Urgent:Asp.Net 3.5 Is there any limitation for sending message? Email delivery is failing when message is little large
Hi Experts!
In the asp.net 3.5, C# I am using Text box with multiline property. I am using smtp to send the email.
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
I am filling up all other values like To, Cc etc., and then getting the textbox text to fill the message body:
message.Body = txtboxmessage.Text.ToString();
I observe that when the textbox has very less lines of text, it sends mail successfully. However, when it cosists of more lines of text, it fails.
Can anyone advise me how to overcome this problem?
Also, please advise how to create email in such way that HTML markup can be added to the message (just like gmail or yahoo or anyother general emails)?
Appreciate quick responses.
Thanks
Dinesh KumarPosted Dec 9, 2009, 1:24 PM
Use iframe instead of using textarea . Use this into relevant area of aspx page.
<iframe id='txtDescription' style="background-color:White;display:block;height:380px;width:100%;border:solid 1px #7F9DB9; " runat="server">iframe>
<input type="hidden" name="hdnIds" id="Hidden1" runat="server" />
//put this code inside ur script
var iframe = document.getElementById('txtDescription');
iframe.contentWindow.document.designMode = "on";
function getValue()
{
var iframe = document.getElementById('txtDescription');
document.getElementById('Hidden1').value = iframe.contentWindow.document.body.innerHTML;
}
function setValue()
{
var iframe = document.getElementById('txtDescription');
iframe.contentWindow.document.write(document.getElementById('Hidden1').value);
}
//Call setValue in body onload.
<body onload="setValue();">
//Call getValue in the onclientclick of send button
<asp:Button ID="btnSend" runat="server" CssClass="input_button" OnClientClick="getValue();" Text="Send" OnClick="btnSend_Click"/>
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
string strToAddress = txtToAddress.Text.ToString();
string strMailContent = Hidden1.Value;
string strMailSubject = txtSubject.Text.ToString();
string strCCAddress = string.Empty;
if (txtCcAddress.Text.ToString() != "")
{
strCCAddress = txtCcAddress.Text.ToString();
}
//This below funtion is to send mail
if (fnSMTPMailSend(strMailContent, strMailSubject, strToAddress, strCCAddress))
{
ShowMessage("Mail sending success!");
}
else
{
ShowMessage("Mail delivery failed. Please retry.");
}
}
catch (Exception ex)
{
HandleError(ex);
}
}
public bool fnSMTPMailSend(string strMailContent, string strSubject, string strToAddress, string strCCAddress)
{
//ur code..
objMailMessage.Body = strMailContent;
objMailMessage.IsBodyHtml = true;
//then ur code..
}
Don't forget to check if it helps..
Thanks & Regards
Dinesh Kumar
Kirtan PatelPosted Dec 7, 2009, 5:51 PM
Sam HobbsPosted Dec 7, 2009, 3:35 PM
Are you sure that your connection's upload speed is fast enough?
MokshasriPosted Dec 7, 2009, 1:16 PM
My message is hardly in KBs and no attachments also, but still it is failing. Can you please provide a sample code in asp.net and C# where it is possible to message of size within this limit say 1MB?
Appreciate if you can provide a sample working code so that I can learn.
Thanks.
Hiren SoniPosted Dec 7, 2009, 1:14 PM
Kirtan PatelPosted Dec 7, 2009, 1:08 PM
for Allowing HTML in body write code like below .
mail.IsBodyHtml = true;
mail only allow 25 MB data send in one mail message :)
if still need assistance then read below article
http://www.codedigest.com/Articles/ASPNET/95_Sending_Email_using_C__and_ASPNet_20.aspx
please check "do you like this answer" check box if it helps you :)