473,548 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write Mime messages in C-sharp?

I have a Java code that I want to convert it to C-sharp in order to put it in my ASP.NET web application.

I used the JLCA (Java Language Conversion Assistant) for conversion, but it gave me many errors indicating that there are not matches in .NET for those Java classes!!

The Java code is:

*************** *************** *************** *************** *****

import java.util.Prope rties;
import javax.mail.*;
import javax.mail.inte rnet.*;
import javax.activatio n.*;

public class Sender
{
public static void main(String [] args)
{
try
{
Properties props = System.getPrope rties();

props.put("mail .smtp.host","lo calhost");

Session session = Session.getDefa ultInstance(pro ps,null);

session.setDebu g(true);

MimeMessage message = new MimeMessage(ses sion);

message.setFrom (new InternetAddress ("us**@host.net ","The user"));

message.addReci pient(Message.R ecipientType.TO , new InternetAddress ("us***@host2.c om","User2")) ;

message.addHead er("Mime-Version","1.0") ;

MimeMultipart multipart = new MimeMultipart(" related");

message.setCont ent(multipart);

message.writeTo (System.out);
MimeBodyPart messageBodyPart = new MimeBodyPart();

//Part 1

DataSource source = new FileDataSource( "d:\\mmw\\real_ logo.jpg");

messageBodyPart .setDataHandler (new DataHandler(sou rce));

messageBodyPart .setHeader("Con tent-ID", "real_logo.jpg" );

messageBodyPart .setFileName("r eal_logo.jpg");

multipart.addBo dyPart(messageB odyPart);

//Part 2

messageBodyPart = new MimeBodyPart();

source = new FileDataSource( "d:\\mmw\\hi.tx t");

messageBodyPart .setDataHandler (new DataHandler(sou rce));

messageBodyPart .setHeader("Con tent-ID", "hi.txt");

messageBodyPart .setFileName("h i.txt");

multipart.addBo dyPart(messageB odyPart);
Transport.send( message);

}
catch(Exception e){System.err.p rintln(""+e);}

}

}
*************** *************** *************** *************** *****

Does anyone know the equivalent C-sharp code?
i.e, I need to make more than 1 mime part with different content-types and content-ids in one message!!

Or is there a software to convert my code to C-sharp directly?

Looking forward to hearing from you!!
HishHish
Nov 16 '05 #1
2 3885
you have to use the

using System.Web.Mail

then create the object using the class MailMessage

e.g. MailMessage m_objMail = new MailMessage()

then use the properties as needed

Cheers
Jonathan Rucker
-- http://www.novaworks.com.au
Nov 16 '05 #2
Hi Jonathan

Thanks for your reply.

Actually I have been searching for appropriate classes and properties. I used MimePart, MailMessage, etc. but I couldn't find how to make different Mime parts with different Content-Types and Content-Ids within ONE message!!

Using the MimePart class, I couldn't find how to specify Content-Type and Content-Id for the MimePart object!

Also MailMessage body can only be set to a string!! So how can I set it to MimeMultipartRe lated class or other Mime classes??

//HishHish
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2719
by: Alberto | last post by:
I am struggling with the php mail function so to allow a multipart mime settings where both the message and any set of attachments can be allowed. Teorically, I'd know how to do. I build up my headers and pass them as the fourth argument of the function mail(). Practically, what happens is that whenever I try to test my script emailing...
3
7703
by: Erik Rosenbach | last post by:
I have a question about how to parse out mime from a message. I have email messages that are stored in a database table and these messages have mime headers embedded within them. How can I parse out this mime content and retrieve only the text messages? Thank you, Erik
1
7007
by: John B. Kim | last post by:
I am working on the code below: ****************************************************** use strict; use MIME::Lite; use Net::SMTP; my $from = 'steve@earthlink.net'; my @addweek1 = qw(michael@earthlink.net jennifer@aol.com ); my $Fnameweek1 = 'JNIssue11.pdf';
1
5383
by: Zev Steinhardt | last post by:
I'm trying to use Mime::Lite to send out multipart messages. So far, it all seems to work well except for one small part. I want to display a "real name" along with the email address when I send out the emails. Unfortuantely, whenever I do so, it gets bounced by the program as an invalid email address. For example, this works: $msg =...
2
1329
by: aurora00 | last post by:
Looking at the email package, it seems all the MIMExxx classes takes string but not file object as the payload. I need to handle very large MIME messages say up to 100M. And possibly many of them. Is email package sufficient. If not is it possible to extend it? Looking at a previous thread it seems the standard library is not sufficient. ...
3
2733
by: John Mark Howell | last post by:
I've got a MIME message that was originally an HTML email with embedded images. When the email is received (to GMail) it is now in MIME format. The HTML portion is now split out into the HTML and the images (each in a MIME part). The MIME part for the image looks like some sort of abreviated compressed code. Does anyone know how to extract...
0
2330
by: Klaus Bonadt | last post by:
I would like to parse an email, which I receive from a pop3 account. While the subject and the sender's email address are probably easy to determine, the body seems to be more difficult because of multi-part messages in MIME format. I am interested only in the plain text. Do you know an easy way to retrieve plain text of the body from an...
11
3084
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a non-trivial exercise. inserting '&lt;' and '&gt;' causes the browser to write the text to the page as literal text rather than as the intended script element. ...
3
10948
by: b. dougherty | last post by:
Greetings all- I am trying to extract subject headers from emails that have been saved as text files. The subject headers are in MIME UTF-8 format, and so they appear like this: subject: =?utf-8?B?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21iczsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?= ...
3
3824
by: Steven Allport | last post by:
I am working on processing eml email message using the email module (python 2.5), on files exported from an Outlook PST file, to extract the composite parts of the email. In most instances this works fine, the message is read in using message_from_file, is_multipart returns True and I can process each component and extract message attachments....
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6036
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.