[Mono-bugs] [Bug 570930] New: System.Net.Mail.Attachment ArgumentNullException
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Fri Jan 15 05:55:11 EST 2010
http://bugzilla.novell.com/show_bug.cgi?id=570930
http://bugzilla.novell.com/show_bug.cgi?id=570930#c0
Summary: System.Net.Mail.Attachment ArgumentNullException
Classification: Mono
Product: Mono: Class Libraries
Version: 1.2.0
Platform: x86-64
OS/Version: Windows 7
Status: NEW
Severity: Normal
Priority: P5 - None
Component: System
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: dr0zaxx at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64;
Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;
Media Center PC 6.0; .NET4.0C; FDM)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AttachFile("/root/Status_Log.txt");
}
static void AttachFile(string file)
{
MailAddress toAddress = new MailAddress("user at gmail.com");
MailAddress fromAddress = new MailAddress("user at gmail.com");
MailMessage mm = new MailMessage(fromAddress, toAddress);
mm.Subject = "Test Subject";
Attachment mailAttachment = new Attachment(file);
mm.Attachments.Add(mailAttachment);
mm.IsBodyHtml = true;
mm.BodyEncoding = System.Text.Encoding.UTF8;
SendMail(mm);
}
static void SendMail(MailMessage mm)
{
try
{
string smtpHost = "smtp.gmail.com";
string userName = "user at gmail.com";
string password = "password";
SmtpClient mClient = new SmtpClient();
mClient.Port = 587;
mClient.EnableSsl = true;
mClient.UseDefaultCredentials = false;
mClient.Credentials = new NetworkCredential(userName,
password);
mClient.Host = smtpHost;
mClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mClient.Send(mm);
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
}
}
}
}
The code returns the following when executed on Ubuntu Linux:
System.ArgumentNullException: Argument cannot be null.
Parameter name: content
at System.Net.Mail.Attachment.CreateAttachmentFromString (System.String
content, System.String name, System.Text.Encoding contentEncoding,
System.String mediaType) [0x00000]
at System.Net.Mail.SmtpClient.SendWithAttachments
(System.Net.Mail.MailMessage message) [0x00000]
at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message)
[0x00000]
at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage
message) [0x00000]
at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message)
[0x00000]
[Test]
AttachFile("/root/Status_Log.txt"); for Linux
AttachFile(@"C:\Status_Log.txt"); for Windows
[Result]
Exception as stated above - Linux
Mail with attachment successfully sent and received in inbox - Windows
Reproducible: Always
Steps to Reproduce:
1. Compile the code above for both Linux and Windows
2. Execute the Windows example. Mail will be sent successfully with attachment.
3. Execute the Linux example. Exception as stated above will occur.
Actual Results:
Mail should be sent with both examples.
Expected Results:
Unable to send mail with attachment with Linux example.
Working for Windows.
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list