Free Support Forum - aspose.com

Using aspose email with Unsubscribe link

Hi I am using aspose email for sending bulk emails. I have implemented unsubscribe hyper link in email body

DirectoryInfo dirInfo = new DirectoryInfo("…/…/ToEmaillist/" + EmailBodyFileName);
Document wordDocument = new Document(dirInfo.FullName);
MemoryStream mhtmlStream = new MemoryStream();
DocumentBuilder builder = new DocumentBuilder(wordDocument);
string UnsubscribeEmail = “https://jobcenterofwisconsin.com/Presentation/unsubscribe.aspx?Email=” + toemail + “”;
builder.InsertHyperlink(“Click here to Unsubscribe”, UnsubscribeEmail, false);
//builder.InsertHyperlink(“Click here to Unsubscribe”, “https://jobcenterofwisconsin.com/Presentation/unsubscribe.aspx?Email= Request.QueryString(‘Email’)”, false);
ArrayList runs = new ArrayList();
Node Separator = null;
foreach (FieldStart fStart in builder.CurrentParagraph.GetChildNodes(NodeType.FieldStart, true))
{
if (fStart.FieldType == FieldType.FieldHyperlink)
{
Separator = fStart.GetField().Separator;
Node currentNode = Separator;
while (currentNode.NodeType != NodeType.FieldEnd)
{
if (currentNode.NodeType == NodeType.Run)
runs.Add(currentNode);
currentNode = currentNode.NextSibling;
}
foreach (Run run in runs)
{
run.Remove();
}
}
}
Run runNode = new Run(wordDocument);
runNode.Text = “Click here to Unsubscribe”;
runNode.Font.Bold = true;
Separator.ParentNode.InsertAfter(runNode, Separator);
builder.Font.ClearFormatting();
wordDocument.Save(mhtmlStream, SaveFormat.Mhtml);
mhtmlStream.Position = 0;
foreach (string item in SendingEmailList)
{
Aspose.Email.MailMessage message = Aspose.Email.MailMessage.Load(mhtmlStream, new MhtmlLoadOptions());
if (AttachmentFileName != “Csv” && !string.IsNullOrEmpty(AttachmentFileName))
{
message.Attachments.Add(new Aspose.Email.Attachment("…/…/ToEmaillist/" + AttachmentFileName));
}
var body = new StringBuilder();
body.Append(message.HtmlBodyText);
// body.Append("<a href=‘https://jobcenterofwisconsin.com/Presentation/unsubscribe.aspx’> login");
message.To.Add(item.ToString());
if (!string.IsNullOrEmpty(ccEmail))
message.CC = ccEmail;
if (!string.IsNullOrEmpty(bccEmail))
message.Bcc = bccEmail;
message.From = fromEmail;
message.Subject = subject.ToString();
var client = new Aspose.Email.Clients.Smtp.SmtpClient(smtpserver.ToString());
try { client.Send(message); }

this is my code problem here is unsubscribe link is coming on the top of the email.I need it in the bottom of the email can u help me on this

@sandeepr,

The code you have shared is not compilable and we are not able to make use of it. Please share with us runnable code and input as well as expected output files for further assistance from our end. We’ll look into it for assisting you further.